如何完全卸载使用npm安装的所有内容(即如何确保重新安装npm)?

3
我在使用Angular和ng等技术时遇到了一些版本问题。我想从头开始,卸载所有已安装的内容并重新开始。我的操作系统是Windows。
我在这里找到了一些信息:https://docs.npmjs.com/misc/removing-npm.html
我在cmd命令行中运行了以下命令,但似乎没有任何效果: npm uninstall npm -g
我以管理员身份重新运行了它,它删除了我安装的一些东西,但不是全部。
以下是非管理员运行的cmd命令行:
C:\>npm uninstall npm -g
up to date in 0.12s

C:\>ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 9.1.1
Node: 12.16.2
OS: win32 x64

Angular: 9.1.1
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.901.1
@angular-devkit/build-angular     0.901.1
@angular-devkit/build-optimizer   0.901.1
@angular-devkit/build-webpack     0.901.1
@angular-devkit/core              9.1.1
@angular-devkit/schematics        9.1.1
@angular/cdk                      7.3.7
@angular/material                 7.3.7
@ngtools/webpack                  9.1.1
@schematics/angular               9.1.1
@schematics/update                0.901.1
rxjs                              6.5.5
typescript                        3.8.3
webpack                           4.42.0

以管理员身份运行后,剩下的内容如下:

c:\>ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 9.1.1
Node: 12.16.2
OS: win32 x64

Angular:
...
Ivy Workspace:

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.901.1
@angular-devkit/core         9.1.1
@angular-devkit/schematics   9.1.1
@schematics/angular          9.1.1
@schematics/update           0.901.1
rxjs                         6.5.4


c:\>

我认为问题的一部分在于我不理解全局安装和仅针对当前项目的安装之间的区别。我开始深入研究这个问题:https://docs.npmjs.com/。还有其他参考资料可以详细解释每个命令的功能吗? - John
任何你用 -g 添加的内容都是全局的。它们通常被用来直接快速启动一些东西,例如 create-react-app。在你的 package.json 中的 dependencies 是特定于你的项目的,而 devDependencies 只在开发模式下可用,并且不会安装到生产环境中。https://docs.npmjs.com/cli-documentation/cli 这些都是简要命令。 - Hadi Pawar
2个回答

3

这个 package.json 文件中的命令可能很有用。你也可以手动删除 node_modules 文件夹,调整 package.json 中的依赖项并重新安装。

"build": "npm build",
"clean": "rm -rf node_modules", 
"reinstall": "npm run clean && npm install", 
"rebuild": "npm run clean && npm install && npm run build",

编辑:我忘记在Windows上放置清理命令了: "clean":"rmdir /s /q node_modules"

如果你的问题是关于全局的angular/cli包,你可以执行以下操作: 使用npm uninstall -g angular-cli卸载angular/cli。 使用npm cache clean清理存储在您用户名下的应用数据文件夹中的npm缓存。 使用npm cache verify验证您的缓存是否已损坏。 使用npm cache verify --force从系统中清除所有缓存。

注意: 您还可以通过以下路径删除 C:\Users\"Your_syste_User_name"\AppData\Roaming\npm 和 C:\Users\"Your_syste_User_name"\AppData\Roaming\npm-cache 然后使用以下命令在您的系统中全局安装最新的angular/cli版本。 npm install -g @angular/cli@latest


1
如果你在使用 angular/cli 时遇到问题,请使用以下命令: npm uninstall -g angular-cli 卸载 angular/cli。 npm cache clean 清理你的 npm 缓存,该缓存位于你的用户名下的应用程序数据文件夹中。 使用 npm cache verify 来验证你的缓存是否已损坏。 使用 npm cache verify --force 来清理你系统中的整个缓存。
注意:如果上述命令不起作用,请尝试使用 -f 或 -force 标志。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接