[英]Create package.json from package-lock.json
I downloaded a theme and it has a package-lock.json file but no package.json file.我下载了一个主题,它有一个 package-lock.json 文件,但没有 package.json 文件。 Is there a way I can generate the package.json from the package-lock.json file.
有没有办法可以从 package-lock.json 文件生成 package.json。 How do I install the node modules with just the package-lock.json file.
如何仅使用 package-lock.json 文件安装节点模块。 Is there a way to do that?
有没有办法做到这一点?
Install the latest npm with npm install -g npm
使用
npm install -g npm
Run npm init
and respond to the questions.运行
npm init
并回答问题。
The above command will generate a package.json
and include the existing packages listed in package-lock.json
上述命令将生成一个
package.json
并包含package-lock.json
中列出的现有包
I think I figured it out.我想我想通了。
I don't think npm init
can draw from package-lock.json.我不认为
npm init
可以从 package-lock.json 中提取。 However it does seem to pull from what is already in your /node_modules .但是,它似乎确实从您/node_modules中已有的内容中提取。 I believe this is why @Harry B's solution works for some and not at all for others.
我相信这就是为什么@Harry B 的解决方案适用于某些人而不适用于其他人的原因。
For example, if you have just cloned your project which contains package-lock.json, no package.json, and empty/non-existence node_modules, npm init
won't create any dependencies.例如,如果您刚刚克隆了包含 package-lock.json、没有 package.json 和空/不存在的 node_modules 的项目,
npm init
不会创建任何依赖项。 However, if you run npm install pkg1 pkg2 pkg3 ...
then run npm init
it will create the dependencies in package.json.但是,如果您运行
npm install pkg1 pkg2 pkg3 ...
然后运行npm init
它将在 package.json 中创建依赖项。
https://pravnyadv.github.io/unpackage/ seems to work. https://pravnyadv.github.io/unpackage/似乎有效。 Copy your package lock file text in, hit the button, copy out the text into a new package.json file.
复制你的包锁定文件文本,点击按钮,将文本复制到一个新的 package.json 文件中。
package-lock.json file relies on the presence of a package.json file, So it's not possible to retrieve package.json (happy to be proved wrong). package-lock.json文件依赖于package.json文件的存在,因此无法检索package.json (很高兴被证明是错误的)。
So a possible solution left is to use a module like auto-install which is capable of generating package.json from the project file dependencies.所以剩下的一个可能的解决方案是使用像auto-install这样的模块,它能够从项目文件依赖项中生成package.json 。
First, you need to install the module globally npm install -g auto-install
.首先,您需要全局安装模块
npm install -g auto-install
。 Then run npm init
and answer the basic requirements.然后运行
npm init
并回答基本要求。
Then, run auto-install
in your project root directory.然后,在项目根目录中运行
auto-install
。 All the dependencies should reflect in package.json file.所有依赖项都应反映在package.json文件中。
** **
** **
Run npm ci
which bypasses a package's package.json to install modules from a package's lockfile.运行
npm ci
绕过包的 package.json 以从包的锁定文件中安装模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.