简体   繁体   English

安装新软件包时,将删除未保存的已安装NPM软件包

[英]NPM package installed without saving are getting removed when new package is being installed

I have a project in Express.js where I need to install new packages, to add new features. 我在Express.js中有一个项目,我需要在其中安装新软件包,以添加新功能。 However, when I am installing new packages, some of the old packages (probably which weren't installed with save command), are getting uninstalled. 但是,当我安装新软件包时,一些旧软件包(可能未使用save命令安装)将被卸载。 Is there a way, package.json can be updated by reading package-lock.json dependencies, so new dependencies do not remove older ones? 有没有办法通过读取package-lock.json依赖项来更新package.json,所以新的依赖项不会删除旧的依赖项?

Suggestions would be highly appreciated! 建议将不胜感激! Thanks. 谢谢。

Update npm 5: 更新npm 5:

As of npm 5.0.0, installed modules are added as a dependency by default, so the --save option is no longer needed. 从npm 5.0.0开始,默认情况下已安装的模块作为依赖项添加,因此不再需要--save选项。 The other save options still exist and are listed in the documentation for npm install. 其他保存选项仍然存在,并在npm安装文档中列出。

Before NPM 5: 在NPM 5之前:

Before version 5, NPM simply installed a package under node_modules by default. 在版本5之前,默认情况下,NPM只是在node_modules下安装了一个软件包。 When you were trying to install dependencies for your app/module, you would need to first install them, and then add them (along with the appropriate version number) to the dependencies section of your package.json. 当您尝试为应用程序/模块安装依赖项时,您需要先安装它们,然后将它们(以及适当的版本号)添加到package.json的依赖关系部分。

The --save option instructed NPM to include the package inside of the dependencies section of your package.json automatically, thus saving you an additional step. --save选项指示NPM自动将软件包包括在package.json的dependencies部分中,从而为您节省了额外的步骤。

In addition, there are the complementary options --save-dev and --save-optional which save the package under devDependencies and optionalDependencies, respectively. 此外,还有补充选项--save-dev和--save-optional,它们分别将软件包保存在devDependencies和optionalDependencies下。 This is useful when installing development-only packages, like grunt or your testing library. 在安装仅限开发的软件包(例如grunt或测试库)时,这很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM