有没有一个简单的方法重新安装我的应用程序所依赖的所有包(即他们在我的应用程序node_modules文件夹)?
正确的方法是执行npm update。这是一个非常强大的命令,它更新丢失的包,还检查是否已经安装的包的新版本可以使用。
阅读NPM介绍,了解你可以用NPM做什么。
大多数情况下,我使用以下命令来完成所有节点模块的完整重新安装(确保您在项目文件夹中)。
rm -rf node_modules && npm install
你也可以在删除node_modules文件夹后运行npm cache clean,以确保没有任何缓存的依赖项。
npm更新了用于安装的CLI命令,并添加了——force标志。
npm install --force
——force(或-f)参数将强制npm获取远程资源,即使磁盘上存在本地副本。
参见npm install
你可以使用npm中找到的重装模块。
安装完成后,可以使用以下命令:
reinstall
与手动删除node_modules文件夹和安装npm的唯一区别是这个命令会自动清除npm的缓存。因此,您可以在一个命令中获得三个步骤。
Upd: NPX重装是一种不需要全局安装包的方式(仅适用于npm5+)
你可以在Windows上使用
(if exist node_modules rmdir node_modules /q /s) && npm install
删除node_modules目录,然后执行NPM安装。安装前删除可确保重新安装所有包。
请按照此步骤重新安装节点模块并进行更新
即使node_modules文件夹不存在也可以工作。现在同步执行以下命令。你也可以使用“npm update”,但我认为这是更可取的方式
npm outdated // not necessary to run this command, but this will show outdated dependencies
npm install -g npm-check-updates // to install the "ncu" package
ncu -u --packageFile=package.json // to update dependencies version in package.json...don't run this command if you don't need to update the version
npm install: will install dependencies in your package.json file.
如果你对包中依赖项的版本没有问题。Json文件,不需要遵循这些步骤,只需运行
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
推荐文章
- npm start和npm run start的区别
- 有没有办法修复包锁。json lockfileVersion所以npm使用特定的格式?
- 如何使用npm全局安装一个模块?
- 实时http流到HTML5视频客户端的最佳方法
- 使用node.js下载图像
- Node.js Express中的HTTP GET请求
- Node.js:将文本文件读入数组。(每一行都是数组中的一项。)
- npm犯错!错误:EPERM:操作不允许,重命名
- Node Sass还不支持当前环境:Linux 64位,带false
- 我如何添加环境变量启动。VSCode中的json
- 解析错误:无法读取文件“…/tsconfig.json”.eslint
- 编译typescript时'tsc命令未找到'
- 在Node.js中'use strict'语句是如何解释的?
- 当WebSockets可用时,为什么要使用AJAX ?
- 使用过程。TypeScript中的env