How to undo npm update?

2020-07-02 08:46发布

问题:

Is there a way to undo the command npm update? I ran the command and now I have a bunch of unmet dependencies and some errors.

I'm trying to manually reinstall and fix all the errors but does anyone know how to essentially revert an npm update?

回答1:

You can restore your package.json file to its previous state (hopefully you still have that, or at least remember what you had changed), and then do another npm update.

[UPDATE]

However, in general, this technique does not guarantee that your entire dependency tree will be restored to its exact former state (since the package.json files in a dependency tree often loosely specify dependency versions).

If you need to ensure that your package's dependency tree can be restored exactly, you have to use something like npm shrinkwrap to "lock down" the dependency versions (before you publish the package).



回答2:

Do this:

git log

then Copy the latest latest key. This will let you checkout your latest commit.

git checkout "your-key" package.json
git checkout "your-key" package-lock.json 

without the " quotes

(package-lock.json is really necessary, but I like to do et anyway - "Just to make sure...")

you can do a

git status

to make sure that your package.json and package.lock

You can also do the

rm -rf node_modules/ 

which will delete node_modules folder

npm install


回答3:

All I did was to do "rm -rf node_modules" to uninstall the updated node_modules and then "npm install" to reinstall them; my package.json hadn't change when I did npm update which caused all the havoc. So by deleting and reinstalling node_modules I'm gladly back in business.



回答4:

git checkout "your-key" package.json
git checkout "your-key" package-lock.json 

without the " quotes

(package-lock.json isn't really necessary, but I like to do it anyway - "Just to make sure...")

You can do a

git status


标签: node.js npm