[英]Is there a way to force npm to generate package-lock.json?
I deleted it by accident and have made many changes to package.json
since.我不小心删除了它,从那以后对package.json
做了很多更改。 An npm install
or npm update
do not generate package-lock.json
anymore. npm install
或npm update
不再生成package-lock.json
。 I tried clearing my npm cache and my nvm cache, but nothing seems to be working.我尝试清除我的 npm 缓存和我的 nvm 缓存,但似乎没有任何效果。 I tried it on several versions of Node.js (6.10.3 Node.js - 3.10.10 npm is what I would like it to work on), and it doesn't work on any.我在多个版本的 Node.js 上尝试过它(6.10.3 Node.js - 3.10.10 npm 是我希望它可以使用的),但它在任何版本上都不起作用。
Is there a way to force npm to generate the package-lock.json
file?有没有办法强制 npm 生成package-lock.json
文件?
In npm 6.x and 7.x you can use在 npm 6.x 和 7.x 中你可以使用
npm i --package-lock-only
According to https://docs.npmjs.com/cli/install.html根据https://docs.npmjs.com/cli/install.html
The --package-lock-only argument will only update the package-lock.json, instead of checking node_modules and downloading dependencies. --package-lock-only 参数只会更新 package-lock.json,而不是检查 node_modules 和下载依赖项。
By default, package-lock.json
is updated whenever you run npm install
.默认情况下,每次运行npm install
时都会更新package-lock.json
。 However, this can be disabled globally by setting package-lock=false
in ~/.npmrc
.但是,这可以通过在~/.npmrc
设置package-lock=false
来全局禁用。
When the global package-lock=false
setting is active, you can still force a project's package-lock.json
file to be updated by running:当全局package-lock=false
设置处于活动状态时,您仍然可以通过运行来强制更新项目的package-lock.json
文件:
npm install --package-lock
This command is the only surefire way of forcing a package-lock.json
update.此命令是强制package-lock.json
更新的唯一package-lock.json
。
This is answered in the comments;这在评论中得到了回答; package-lock.json
is a feature in npm
v5 and higher. package-lock.json
是npm
v5 及更高版本中的一项功能。 npm shrinkwrap
is how you create a lockfile in all versions of npm
. npm shrinkwrap
是你在所有版本的npm
创建锁文件的方式。
As several answer explained the you should run:正如几个答案所解释的那样,您应该运行:
npm i
BUT if it does not solve...但是如果它没有解决......
Check the version of your npm
executable.检查npm
可执行文件的版本。 (For me it was 3.xx which doesn't uses the package-lock.json
(at all)) (对我来说,它是 3.xx,它不使用package-lock.json
(根本))
npm -v
It should be at least 5.xx (which introduced the package-lock.json file.)它应该至少是 5.xx (它引入了 package-lock.json 文件。)
To update npm
on Linux, follow these instructions.要在 Linux 上更新npm
,请按照以下说明进行操作。
For more details about package files, please read this medium story.有关包文件的更多详细信息,请阅读此媒体故事。
If your npm version is lower than version 5 then install the higher version for getting the automatic generation of package-lock.json .如果您的npm版本低于版本 5,请安装更高版本以获得package-lock.json的自动生成。
Example: Upgrade your current npm to version 6.14.0示例:将您当前的npm升级到版本 6.14.0
npm i -g npm@6.14.0
You could view the latest npm version list by您可以通过以下方式查看最新的npm版本列表
npm view npm versions
当使用本地包时,我发现可靠地重新生成 package-lock.json 文件的唯一方法是删除它,以及在链接的模块和所有相应的 node_modules 文件夹中,并让它使用npm i
重新生成
I deleted it by accident and have made many changes to package.json
since.我无意中将其删除,此后对package.json
进行了许多更改。 An npm install
or npm update
do not generate package-lock.json
anymore. npm install
或npm update
不再生成package-lock.json
。 I tried clearing my npm cache and my nvm cache, but nothing seems to be working.我试图清除我的npm缓存和nvm缓存,但是似乎没有任何作用。 I tried it on several versions of Node.js (6.10.3 Node.js - 3.10.10 npm is what I would like it to work on), and it doesn't work on any.我在多个版本的Node.js(6.10.3 Node.js-3.10.10 npm是我希望使用的版本)上进行了尝试,但在任何版本上均不起作用。
Is there a way to force npm to generate the package-lock.json
file?有没有办法强制npm生成package-lock.json
文件?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.