node.js 如何使用 npm 重新安装应用程序的依赖项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12866494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you reinstall an app's dependencies using npm?
提问by trusktr
Is there a simple way to reinstall allpackages that my app depends on (i.e. they are in my apps node_modules folder)?
有没有一种简单的方法来重新安装我的应用程序依赖的所有包(即它们在我的应用程序 node_modules 文件夹中)?
回答by Vadim Baryshev
The easiest way that I can see is delete node_modulesfolder and execute npm install.
我能看到的最简单的方法是删除node_modules文件夹并执行npm install.
回答by himanshu
The right way is to execute npm update. It's a really powerful command, it updates the missing packages and also checks if a newer version of package already installed can be used.
正确的方法是执行npm update. 这是一个非常强大的命令,它更新丢失的包并检查是否可以使用已安装的较新版本的包。
Read Intro to NPMto understand what you can do with npm.
阅读NPM 简介以了解您可以使用 npm 做什么。
回答by 0x1ad2
Most of the time I use the following command to achieve a complete reinstall of all the node modules (be sure you are in the project folder).
大多数时候我使用以下命令来实现所有节点模块的完整重新安装(确保您在项目文件夹中)。
rm -rf node_modules && npm install
You can also run npm cache cleanafter removing the node_modulesfolder to be sure there aren't any cached dependencies.
您还可以npm cache clean在删除node_modules文件夹后运行以确保没有任何缓存的依赖项。
回答by Itsik Avidan
npmupdated the CLI command for installand added the --forceflag.
npm更新了 CLI 命令install并添加了--force标志。
npm install --force
The --force(or -f) argument will force npmto fetch remote resources even if a local copy exists on disk.
即使磁盘上存在本地副本,--force(or -f) 参数也将强制npm获取远程资源。
See npm install
回答by deksden
You can use the reinstall modulefound in npm.
您可以使用npm 中的重新安装模块。
After installing it, you can use the following command:
安装后,您可以使用以下命令:
reinstall
The only difference with manually removing node_modulesfolder and making npm installis that this command automatically clear npm's cache. So, you can get three steps in one command.
与手动删除node_modules文件夹和制作的唯一区别npm install是此命令会自动清除 npm 的缓存。因此,您可以在一个命令中完成三个步骤。
upd:npx reinstallis a way to run this command without globally installing package (only for npm5+)
upd:npx reinstall是一种无需全局安装包即可运行此命令的方法(仅适用于 npm5+)
回答by Joeri
You can do this with one simple command:
你可以用一个简单的命令来做到这一点:
npm ci
回答by michal.jakubeczy
For Windows you can use
对于 Windows,您可以使用
(if exist node_modules rmdir node_modules /q /s) && npm install
which removes node_modulesdirectory and performs npm installthen. Removal before install assures that all packages are reinstalled.
它删除node_modules目录并执行npm install。安装前删除可确保重新安装所有软件包。
回答by Pedro JR
Follow this step to re install node modules and update them
按照此步骤重新安装节点模块并更新它们
works even if node_modules folder does not exist. now execute the following command synchronously. you can also use "npm update" but I think this'd preferred way
即使 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.
if you're okay with the version of your dependencies in your package.json file, no need to follow those steps just run
如果您对 package.json 文件中的依赖项版本没问题,则无需执行这些步骤,只需运行
npm install

