node.js 有没有办法强制 npm 生成 package-lock.json?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46653833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:31:47  来源:igfitidea点击:

Is there a way to force npm to generate package-lock.json?

node.jsnpmpackage-lock.json

提问by Big Money

I deleted it by accident and have made many changes to package.jsonsince. An npm installor npm updatedo not generate package-lock.jsonany more. I tried clearing my npm cache and my nvm cache, but nothing seems to be working. 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.

我不小心删除了它,并对其进行了许多更改package.json。的npm installnpm update不产生package-lock.json任何更多。我尝试清除我的 npm 缓存和我的 nvm 缓存,但似乎没有任何效果。我在多个版本的 Node.js 上尝试过它(6.10.3 Node.js - 3.10.10 npm 是我希望它使用的),但它在任何版本上都不起作用。

Is there a way to force npm to generate the package-lock.jsonfile?

有没有办法强制 npm 生成package-lock.json文件?

回答by Mathias Bynens

By default, package-lock.jsonis updated whenever you run npm install. However, this can be disabled globally by setting package-lock=falsein ~/.npmrc.

默认情况下,package-lock.json每次运行时都会更新npm install。然而,这可以通过全局设置禁用package-lock=false~/.npmrc

When the global package-lock=falsesetting is active, you can still force a project's package-lock.jsonfile 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.jsonupdate.

此命令是强制package-lock.json更新的唯一可靠方法。

回答by Janusz Przybylski

In npm 6.x you can use

在 npm 6.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 LJHarb

This is answered in the comments; package-lock.jsonis a feature in npmv5 and higher. npm shrinkwrapis how you create a lockfile in all versions of npm.

这在评论中得到了回答;package-lock.jsonnpmv5 及更高版本中的一项功能。npm shrinkwrap是如何在所有版本的npm.

回答by betontalpfa

As several answer explained the you should run:

正如几个答案所解释的那样,您应该运行:

npm i

npm i

BUTif it does notsolve...

但是如果它没有解决......

Check the version of your npmexecutable.(For me it was 3.x.x which doesn't uses the package-lock.json(at all))

检查npm可执行文件的版本。(对我来说,它是 3.xx,它不使用package-lock.json(根本))

npm -v

npm -v

It should be at least 5.x.x(which introducedthe package-lock.json file.)

它应该至少是 5.xx(它引入了 package-lock.json 文件。)

To update npm on Lunix follow theseinstructions.

要在 Lunix 上更新 npm,请按照以下说明进行操作。

For more details package files of please read this mediumstory.

有关更多详细信息,请阅读此媒体故事的包文件。

回答by SridharKritha

If your npmversion is lowerthan version 5then install the higher version for getting the automatic generation of package-lock.json.

如果您的NPM版本更低5的版本,然后安装高版本用于获取自动生成的包lock.json

Example:Upgrade your current npmto version 6.14.0

示例:将您当前的npm升级到版本 6.14.0

npm i -g [email protected]

You could view the latest npmversion list by

您可以通过以下方式查看最新的npm版本列表

npm view npm versions

回答by Mcanic

package-lock.json is re-generated whenever you run npm i.

每次运行时都会重新生成 package-lock.json npm i