有没有一个简单的方法重新安装我的应用程序所依赖的所有包(即他们在我的应用程序node_modules文件夹)?


当前回答

我能看到的最简单的方法是删除node_modules文件夹并执行npm install。

其他回答

我能看到的最简单的方法是删除node_modules文件夹并执行npm install。

正确的方法是执行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 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.