node.js 如何撤消 npm 更新?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27954247/
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:19:01  来源:igfitidea点击:

How to undo npm update?

node.jsnpm

提问by aug

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.

有没有办法撤消命令npm update?我运行了命令,现在我有一堆未满足的依赖项和一些错误。

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

我正在尝试手动重新安装并修复所有错误,但有没有人知道如何从本质上恢复npm update?

采纳答案by cybersam

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

您可以将package.json文件恢复到以前的状态(希望您仍然拥有该状态,或者至少记住您更改的内容),然后执行另一个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.jsonfiles in a dependency tree often loosely specify dependency versions).

然而,一般来说,这种技术并不能保证你的整个依赖树将恢复到原来的状态(因为package.json依赖树中的文件通常松散地指定依赖版本)。

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

如果你需要确保你的包的依赖树可以准确地恢复,你必须使用类似npm shrinkwrap 的东西来“锁定”依赖版本(你发布包之前)。

回答by cybersam

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...")

(package-lock.json 真的很有必要,但我还是喜欢这样做——“只是为了确保......”)

you can do a

你可以做一个

git status

to make sure that your package.jsonand package.lock

以确保您package.jsonpackage.lock

You can also do the

你也可以这样做

rm -rf node_modules/ 

which will delete node_modules folder

这将删除 node_modules 文件夹

npm install

回答by Pablo

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.

我所做的就是执行“rm -rf node_modules”卸载更新的node_modules,然后执行“npm install”重新安装它们;当我进行 npm update 时,我的 package.json 没有改变,这导致了所有的破坏。因此,通过删除并重新安装 node_modules,我很高兴重新开展业务。

回答by Palak Mantry

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

without the " quotes

没有 " 引号

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

package-lock.json并不是真的有必要,但无论如何我都喜欢这样做 - “只是为了确保......”)

You can do a

你可以做一个

git status