当前位置:首页>编程日记>正文

如何在Node JS中卸载NPM模块?

本文翻译自:How to uninstall npm modules in node js?

As commonly known, any npm module can be installed by running a simple command: npm install <module_name> . 众所周知,可以通过运行一个简单的命令来安装任何npm模块: npm install <module_name>

I have installed a few modules that I do not use anymore and I just want to get them off. 我已经安装了一些不再使用的模块,我只想把它们取下来。 I have a few questions regarding this: 我对此有一些疑问:

  • Do we have any command or process to uninstall a module from the root (something like npm uninstall <module_name> ) or will simply removing the module files do? 我们是否有任何命令或过程从根目录卸载模块(类似于npm uninstall <module_name> ),还是只是删除模块文件呢?

  • How does it affect us if we keep the unused modules? 如果我们保留未使用的模块,它将对我们有何影响?


#1楼

参考:https://stackoom.com/question/spCW/如何在Node-JS中卸载NPM模块


#2楼

The command is simply npm uninstall <name> 该命令只是npm uninstall <name>

The nodejs documents https://npmjs.org/doc/ have all the commands that you need to know with npm. nodejs文档https://npmjs.org/doc/具有npm需要了解的所有命令。

A local install will be in the node_modules/ directory of your application. 本地安装将在应用程序的node_modules/目录中。 This won't affect the application if a module remains there with no references to it. 如果模块保留在那里而没有引用,则这不会影响应用程序。

If you're removing a global package however, any applications referencing it will crash. 但是,如果要删除全局软件包,则引用该全局软件包的所有应用程序都将崩溃。

Here are different options: 这是不同的选项:

npm uninstall <name> removes the module from node_modules , but not package.json npm uninstall <name>将从node_modules删除模块,但不会从package.json删除

npm uninstall <name> --save also removes it from dependencies in package.json npm uninstall <name> --save还将其从package.json dependencies中删除

npm uninstall <name> --save-dev also removes it from devDependencies in package.json npm uninstall <name> --save-dev还将其从package.json devDependencies中删除

npm -g uninstall <name> --save also removes it globally npm -g uninstall <name> --save也将其全局删除


#3楼

我只是默认情况下在我的主目录下安装手写笔 ,所以我只使用npm uninstall stylus将其分离,或者您可以尝试使用npm rm <package_name>退出。


#4楼

If it doesn't work with npm uninstall <module_name> try it globally by typing -g . 如果它不能与npm uninstall <module_name>一起npm uninstall <module_name>并通过-g全局尝试。

Maybe you just need to do it as an superUser/administrator with sudo npm uninstall <module_name> . 也许您只需要以sudo npm uninstall <module_name> install sudo npm uninstall <module_name>的超级用户/管理员身份进行操作即可。


#5楼

Well to give a complete answer to this question, there are two methods : (for example we call the installed module as module1) 为了完全回答这个问题,有两种方法 :(例如,我们将已安装的模块称为module1)。

  1. To remove module1 without changing package.json: 要在更改package.json的情况下删除module1:

    npm uninstall module1

  2. To remove module1 with changing package.json, and removing it from the dependencies in package.json: 通过更改package.json来删除module1,并将其从package.json中的依赖项中删除,请执行以下操作:

    npm uninstall --save module1

Note: to simplify the above mentioned commands, you can use -S instead of --save , and can use remove , rm , r , un , unlink instead of uninstall 注意:为简化上述命令,可以使用-S代替--save ,并且可以使用removermrununlink而不是uninstall


#6楼

I found this out the hard way, even if it is seemingly obvious. 即使看起来很明显,我也很难做到这一点。

I initially tried to loop through the node_modules directory running npm uninstall module-name with a simple for loop in a script. 我最初尝试在脚本中使用简单的for循环遍历运行npm uninstall module-name的node_modules目录。 I found out it will not work if you call the full path, eg 我发现如果您调用完整路径,它将无法正常工作,例如

npm uninstall module-name

was working, but 在工作,但是

npm uninstall /full/path/to/node_modules/module-name 

was not working. 没有工作。


http://www.coolblog.cn/news/1994c05ebf12f6da.html

相关文章:

  • asp多表查询并显示_SpringBoot系列(五):SpringBoot整合Mybatis实现多表关联查询
  • s7day2学习记录
  • 【求锤得锤的故事】Redis锁从面试连环炮聊到神仙打架。
  • 矿Spring入门Demo
  • 拼音怎么写_老师:不会写的字用圈代替,看到孩子试卷,网友:人才
  • Linux 实时流量监测(iptraf中文图解)
  • Win10 + Python + GPU版MXNet + VS2015 + RTools + R配置
  • 美颜
  • shell访问php文件夹,Shell获取某目录下所有文件夹的名称
  • 如何优雅的实现 Spring Boot 接口参数加密解密?
  • LeCun亲授的深度学习入门课:从飞行器的发明到卷积神经网络
  • Mac原生Terminal快速登录ssh
  • java受保护的数据与_Javascript类定义语法,私有成员、受保护成员、静态成员等介绍...
  • mysql commit 机制_1024MySQL事物提交机制
  • 支撑微博千亿调用的轻量级RPC框架:Motan
  • jquery 使用小技巧
  • 法拉利虚拟学院2010 服务器,法拉利虚拟学院2010
  • 2019-9
  • vscode pylint 错误_将实际未错误的py库添加到pylint白名单
  • 科学计算工具NumPy(3):ndarray的元素处理
  • linux批量创建用户和密码
  • js常用阻止冒泡事件
  • 工程师在工作电脑存 64G 不雅文件,被公司开除后索赔 41 万,结果…
  • newinsets用法java_Java XYPlot.setInsets方法代碼示例
  • 气泡图在开源监控工具中的应用效果
  • 各类型土地利用图例_划重点!国土空间总体规划——土地利用
  • php 启动服务器监听
  • dubbo简单示例
  • 【设计模式】 模式PK:策略模式VS状态模式
  • [iptables]Redhat 7.2下使用iptables实现NAT
  • Ubuntu13.10:[3]如何开启SSH SERVER服务
  • CSS小技巧——CSS滚动条美化
  • JS实现-页面数据无限加载
  • 阿里巴巴分布式服务框架 Dubbo
  • 最新DOS大全
  • Django View(视图系统)
  • 阿里大鱼.net core 发送短信
  • 程序员入错行怎么办?
  • Sorenson Capital:值得投资的 5 种 AI 技术
  • 两张超级大表join优化
  • 第九天函数
  • Linux软件安装-----apache安装
  • HDU 5988 最小费用流
  • 《看透springmvc源码分析与实践》读书笔记一
  • Arm芯片的新革命在缓缓上演
  • 正式开课!如何学习相机模型与标定?(单目+双目+鱼眼+深度相机)
  • nagios自写插件—check_file
  • python3 错误 Max retries exceeded with url 解决方法
  • 行为模式之Template Method模式
  • 通过Spark进行ALS离线和Stream实时推荐