是否有删除所有全局npm模块的命令?如果没有,你有什么建议?
当前回答
sudo npm list -g --depth=0. | awk -F ' ' '{print $2}' | awk -F '@' '{print $1}' | sudo xargs npm remove -g
为我工作
Sudo NPM list -g——depth=0。列出所有已安装的顶级 awk -F ' ' '{print $2}'摆脱├── awk -F '@' '{print $1}'获取'@'之前的部分 Sudo xargs NPM remove -g全局删除包
其他回答
对于一种更手动的方法,它不涉及文件浏览器,不关心安装在哪里,以后不太可能崩溃,100%跨平台兼容,并且由于额外的步骤而感觉更安全,请使用这种方法。
npm ls -g --depth=0 Copy output Paste into favorite code editor (I use vsCode. Great multi-cursor editing) Check for any packages you'd like to keep (nodemon, yarn, to name a few) Remove those lines Remove every instance of +-- or other line decorators Remove all the version information (eg '@2.11.4') Put all items on same line, space separated Add npm uninstall -g to beginning of that one line. Mine looks like npm uninstall -g @angular/cli @vue/cli express-generator jest mocha typescript bindings nan nodemon yarn, but I didn't install many packages globally on this machine. Copy line Paste in terminal, hit enter if not already added from the copy/paste Look for any errors in the terminal. Check npm ls -g to make sure it's complete. If something got reinstalled, rinse and repeat
其他仅使用cli的方法非常适合计算机管理员从相同的ssh或Puppet同时为100台几乎相同的计算机做一些事情。但如果你只做一次,甚至一年5次,这就容易多了。
对于那些使用Windows的人来说,删除所有全局安装的npm包的最简单的方法是删除以下内容:
C:\用户\用户名\应用数据\漫游\npm
您可以通过在资源管理器、运行提示符或开始菜单中键入%appdata%/npm快速到达那里。
对于使用Powershell的用户:
npm -gp ls --depth=0 | ForEach-Object { Get-Item $_ } | Where { $_.Name -ne 'npm' } | ForEach-Object { npm rm -g $_.Name }
清除缓存。
npm cache clear
简单地使用下面的MAC,
Sudo rm -rf /usr/local/ {bin /{节点,npm}, lib / node_modules / npm、lib /节点,共享/男人/ /节点。}
只要把你的控制台:
Sudo NPM list -g——depth=0。| awk -F ' '{print $2}' | awk -F '@' '{print $1}' | sudo xargs npm remove -g
这是我的工作……
推荐文章
- ReferenceError: description没有定义NodeJs
- 将一个二进制的NodeJS Buffer转换为JavaScript的ArrayBuffer
- AngularJS只适用于单页应用程序吗?
- 如何在vue-cli项目中更改端口号
- 如何查看npm包的大小?
- 同步和异步编程(在node.js中)的区别是什么?
- 如何编辑通过npm安装的节点模块?
- “node_modules”文件夹应该包含在git存储库中吗
- 使用package.json在全局和本地安装依赖项
- this.libOptions.parse不是一个函数
- 对嵌套文件夹运行npm install的最好方法是什么?
- 节点Multer异常字段
- 在Ubuntu上安装Bower
- 很好的初学者教程socket.io?
- CALL_AND_RETRY_LAST分配失败-进程内存不足