npm install not creating a new package-lock.json

后端 未结 5 416
醉梦人生
醉梦人生 2021-02-01 12:49

I accidentally deleted my package-lock.json file. npm install is not generating a new one. How do I get npm to recreate this file.

相关标签:
5条回答
  • 2021-02-01 12:59

    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

    To make sure your .npmrc is not blocking the creation of package-lock file, set this to your .npmrc

    echo 'package-lock=true' >> .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.x.x.

    check your npm version: npm -v

    update your npm to latest version using:

    npm install -g npm@latest

    npm i -g npm-upgrade

    @will

    0 讨论(0)
  • 2021-02-01 13:04

    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.

    FYI. Let's verify what version of node and npm.

    npm -v
    

    prints: x.x.x

    node -v
    

    prints: x.x.x

    I believe for package-lock.json is auto-generated if the 2 conditions npm version > 5.x.x and node version > 7.x.x are met

    Then, try the following steps depending on which version you have:

    npm v5+:

    Regenerate the package-lock.json by running npm install. You may also regenerate the file without actually downloading dependencies by using npm install --package-lock-only

    npm v4.x & earlier:

    1. Generate a npm-shrinkwrap.json by running npm shrinkwrap. 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)
    2. Rename the npm-shrinkwrap.json to package-lock.json
    0 讨论(0)
  • 2021-02-01 13:09

    There might be a file called .npmrc which can contain

    package-lock=false
    

    which will cause the package lock file to not be generated.

    0 讨论(0)
  • 2021-02-01 13:14

    If your npm version is <5 you will have a shrinkwrap.json file created when running npm install.

    Otherwise package-lock will be created on npm versions 5 and above.

    0 讨论(0)
  • 2021-02-01 13:16

    I was also facing the same issue

    I just removed the package-lock=false from .npmrc and now it is creating the lock file

    0 讨论(0)
提交回复
热议问题