Why did package-lock.json change the integrity hash from sha1 to sha512?

后端 未结 7 934
日久生厌
日久生厌 2021-01-31 23:50

I just generated a new npm lockfile, package-lock.json, as part of my typical workflow. But I noticed that this time all of the integrity hashes have been changed from sha1 to s

相关标签:
7条回答
  • 2021-02-01 00:31

    I'm working in big team. Forcing every developer to force clean npm cache is difficult and not reliable. Also, this doesn't help every time. So, for anyone who still facing this npm issue (same as me) and nothing else helps – try this git based tool I've built recently: https://github.com/kopach/lockfix. It reverts sha512 -> sha1 integrity changes of npm's lock files. If you add this to your postshrinkwrap script of package.json - you should eventually get all integrity properties set to sha512 and have lock file consistent.

    npm install --save-dev lockfix
    
    "scripts": {
        "postshrinkwrap": "lockfix",
    },
    
    0 讨论(0)
  • 2021-02-01 00:33

    In my case npm -g i npm was not enough, I had to modify PATH to point new npm at begining.

    To check it without modification try /usr/local/bin/npm i instead of npm i.

    0 讨论(0)
  • 2021-02-01 00:34

    From what I can see, npm changed the integrity checksum from sha1 to sha512.

    If your git changes are going from sha1 to sha512, you should do that update once and it will be good after that.

    If someone else working with the codebase and sees a git change from sha512 down to sha1 (which is the issue I was having) you can fix it by running the following:

    Discard the changes in git for package-lock.json

    npm i -g npm
    rm -rf node_modules/
    npm i
    

    This will update npm and reinstall all of your packages so that the new checksum (sha512) is present.

    0 讨论(0)
  • 2021-02-01 00:34

    Further building on previous comments and suggestions, for me I needed to wipe the existing node_modules folder, the cache, and then grab the sha512 package-lock.json file from git (which was committed from another computer), and finally do an npm i. Something like this:

    npm i -g npm
    rm -rf node_modules/
    npm cache clear --force
    git reset --hard
    npm i
    

    After this package-lock.json used sha512 and other changes stabilized.

    0 讨论(0)
  • 2021-02-01 00:35

    As @Daniel Cumings I also had to remove the package-lock.json to get rid of the sha1 hashes. Here's the Windows CLI commands for reference, which does the same as Daniel's script:

    npm i -g npm
    rd /s /q "node_modules"
    del package-lock.json
    npm cache clear --force
    npm i
    
    0 讨论(0)
  • 2021-02-01 00:38

    Building on what Dave answered. The fix i found was to do the following:

    npm i -g npm
    
    cd {working directory}
    rm -rf node_modules/
    rm package-lock.json
    npm cache clear --force
    npm i
    

    We did this for all our developers at the same time and this stopped the sha-512 vs sha-1 issue which was causing frustrating merge conflicts.

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