简体   繁体   English

npm install 没有创建新的 package-lock.json

[英]npm install not creating a new package-lock.json

I accidentally deleted my package-lock.json file.我不小心删除了我的 package-lock.json 文件。 npm install is not generating a new one. npm install 不会生成新的。 How do I get npm to recreate this file.如何让 npm 重新创建此文件。

There might be a file called .npmrc which can contain可能有一个名为.npmrc的文件可以包含

package-lock=false

which will cause the package lock file to not be generated.这将导致无法生成包锁定文件。

In theory you could also have turned on npm config set package-lock false globally (change to true to turn on again), but that's less likely to happen unintentionally.从理论上讲,您也可以全局打开npm config set package-lock false (更改为true以再次打开),但这不太可能无意中发生。

The package-lock.json file was introduced in npm v5, so the steps you need to take to regenerate package-lock.json depend on which version of npm you're using. package-lock.json 文件是在 npm v5 中引入的,因此您需要采取的重新生成 package-lock.json 的步骤取决于您使用的 npm 版本。

FYI.供参考。 Let's verify what version of node and npm.让我们验证一下 node 和 npm 的版本。

npm -v

prints: xxx打印: xxx

node -v

prints: xxx打印: xxx

I believe for package-lock.json is auto-generated if the 2 conditions npm version > 5.xx and node version > 7.xx are met如果满足 npm 版本 > 5.xx 和节点版本 > 7.xx 的 2 个条件,我相信 package-lock.json 会自动生成

Then, try the following steps depending on which version you have:然后,根据您拥有的版本尝试以下步骤:

npm v5+: npm v5+:

Regenerate the package-lock.json by running npm install .通过运行npm install重新生成 package-lock.json。 You may also regenerate the file without actually downloading dependencies by using npm install --package-lock-only您也可以使用npm install --package-lock-only重新生成文件而不实际下载依赖项

npm v4.x & earlier: npm v4.x 及更早版本:

  1. Generate a npm-shrinkwrap.json by running npm shrinkwrap .通过运行npm shrinkwrap生成一个 npm-shrinkwrap.json。 This file has the same format as package-lock.json and achieves essentially the same purpose in earlier versions of npm (see https://docs.npmjs.com/files/package-lock.json and https://docs.npmjs.com/files/shrinkwrap.json for detailed information on this point)该文件与 package-lock.json 具有相同的格式,并且在 npm 的早期版本中实现了基本相同的目的(请参阅https://docs.npmjs.com/files/package-lock.jsonhttps://docs.npmjs .com/files/shrinkwrap.json有关这一点的详细信息)
  2. Rename the npm-shrinkwrap.json to package-lock.json将 npm-shrinkwrap.json 重命名为 package-lock.json

To resolve this issue I have tried below mentioned things and it worked for me :为了解决这个问题,我尝试了下面提到的事情,它对我有用:

Make sure your package-lock globally enabled, you can enable it using:确保您的包锁全局启用,您可以使用以下方法启用它:

npm config set package-lock true npm config set package-lock true

To make sure your .npmrc is not blocking the creation of package-lock file, set this to your .npmrc要确保您的 .npmrc 不会阻止创建包锁定文件,请将其设置为您的 .npmrc

echo 'package-lock=true' >> .npmrc回声“包锁=真”>>.npmrc

note : package-lock.json is automatically generated for any operations where npm modifies either the node_modules tree, or package.json for npm -v > 5.xx注意:对于 npm 修改 node_modules 树或 npm -v > 5.xx 的 package.json 的任何操作,都会自动生成 package-lock.json

check your npm version: npm -v检查你的 npm 版本: npm -v

update your npm to latest version using:使用以下命令将您的 npm 更新到最新版本:

npm install -g npm@latest npm install -g npm@latest

npm i -g npm-upgrade npm i -g npm-upgrade

@will @将要

Make sure you are in the right folder in the command line (use pwd in Linux/macOS to get the current path you're in).确保您位于命令行中的正确文件夹中(在 Linux/macOS 中使用pwd获取您所在的当前路径)。

I've run npm install many times, just to find out later I was doing it in the wrong folder.我已经运行npm install很多次,只是为了稍后发现我在错误的文件夹中执行它。

I was also facing the same issue我也面临同样的问题

I just removed the package-lock=false from .npmrc and now it is creating the lock file我刚刚从 .npmrc 中删除了package-lock=false ,现在它正在创建锁定文件

If your npm version is <5 you will have a shrinkwrap.json file created when running npm install.如果您的 npm 版本 <5,您将在运行 npm install 时创建一个shrinkwrap.json文件。

Otherwise package-lock will be created on npm versions 5 and above.否则,将在 npm 5 及更高版本上创建package-lock

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM