简体   繁体   English

npm install 不保存对 package.json 的依赖

[英]npm install doesn't save dependency to package.json

It does add only when I execute: npm install <package_name> --save它仅在我执行时添加: npm install <package_name> --save

In the documentation though: https://docs.npmjs.com/cli/install is written this:不过在文档中: https : //docs.npmjs.com/cli/install是这样写的:

By default, npm install will install all modules listed as dependencies in package.json.默认情况下,npm install 将安装 package.json 中列为依赖项的所有模块。

Which is misleading.这是误导。

npm install without arguments installs all dependencies (and dev dependencies) listed in the package.json file. npm install without arguments 安装package.json文件中列出的所有依赖项(和开发依赖项)。

npm install --production installs all the dependencies (but no dev dependency) npm install --production安装所有依赖项(但没有开发依赖项)

npm install <package> installs a package and its dependencies. npm install <package>安装包及其依赖项。

npm install <package> --save installs a package and its dependencies, and adds it in the package.json file. npm install <package> --save安装包及其依赖项,并将其添加到package.json文件中。

Edit: Since npm 5, --save is implied.编辑:从 npm 5 开始,-- --save是隐含的。

No, it's not.不,不是。 I think you are misreading the sentence.我认为你误读了这句话。

npm install without any package name (as in your quote) will install all dependencies mentioned in the package.json. npm install没有任何包名(如你的引用)将安装 package.json 中提到的所有依赖项。

Crete package.json file in your application folder.应用程序文件夹中的 Crete package.json 文件。

Exp:- var/www/html/node/rest/package.json Exp:- var/www/html/node/rest/package.json

{ "name": "node-api", "main": "server.js", "version": "0.0.1", "dependencies": { "express": "~4.0.0", "mongoose": "~3.6.13", "body-parser": "~1.0.1", "mysql": "^2.5.4" } } { "name": "node-api", "main": "server.js", "version": "0.0.1", "dependencies": { "express": "~4.0.0", "mongoose" : "~3.6.13", "body-parser": "~1.0.1", "mysql": "^2.5.4" } }

Then run npm install command your application folder然后运行 ​​npm install 命令你的应用程序文件夹

Exp:- var/www/html/node/rest npm install Exp:- var/www/html/node/rest npm install

你可以再次运行npm init来更新依赖信息。

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

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