有没有一个简单的方法重新安装我的应用程序所依赖的所有包(即他们在我的应用程序node_modules文件夹)?
当前回答
你可以使用npm中找到的重装模块。
安装完成后,可以使用以下命令:
reinstall
与手动删除node_modules文件夹和安装npm的唯一区别是这个命令会自动清除npm的缓存。因此,您可以在一个命令中获得三个步骤。
Upd: NPX重装是一种不需要全局安装包的方式(仅适用于npm5+)
其他回答
npm更新了用于安装的CLI命令,并添加了——force标志。
npm install --force
——force(或-f)参数将强制npm获取远程资源,即使磁盘上存在本地副本。
参见npm install
我能看到的最简单的方法是删除node_modules文件夹并执行npm install。
你可以用一个简单的命令来做到这一点:
npm ci
以下是npm ci文档的节选:
In short, the main differences between using npm install and npm ci are: The project must have an existing package-lock.json or npm-shrinkwrap.json. If dependencies in the package lock do not match those in package.json, npm ci will exit with an error, instead of updating the package lock. npm ci can only install entire projects at a time: individual dependencies cannot be added with this command. If a node_modules is already present, it will be automatically removed before npm ci begins its install. It will never write to package.json or any of the package-locks: installs are essentially frozen.
从npm cli v6.5.0开始,你可以使用backronym:
npm clean-install
来源:
https://github.com/npm/cli/releases/tag/v6.5.0 https://github.com/npm/cli/commit/fc1a8d185fc678cdf3784d9df9eef9094e0b2dec
删除node_module,使用命令重新安装
rm -rf node_modules && npm i
推荐文章
- CALL_AND_RETRY_LAST分配失败-进程内存不足
- 在Ubuntu上安装Node.js
- 使用express.js代理
- Node -使用NODE_MODULE_VERSION 51根据不同的Node.js版本编译
- RabbitMQ / AMQP:单队列,同一消息的多个消费者?
- Node.js同步执行系统命令
- 禁用包的postinstall脚本
- Node.js上的html解析器
- 错误:无法找到模块“webpack”
- 在node.js中使用async / await文件系统
- NodeJS -用NPM安装错误
- 如何为本地安装npm包设置自定义位置?
- 回调函数来处理管道的完成
- Express函数中的“res”和“req”参数是什么?
- node.js TypeError:路径必须是绝对路径或指定根路径到res.sendFile[解析JSON失败]