Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install doesn't save dependency to package.json

Tags:

node.js

npm

It does add only when I execute: npm install <package_name> --save

In the documentation though: https://docs.npmjs.com/cli/install is written this:

By default, npm install will install all modules listed as dependencies in package.json.

Which is misleading.

like image 260
Ondrej Tokar Avatar asked Jul 05 '16 09:07

Ondrej Tokar


People also ask

Does npm install add to package json?

By default, npm install will install all modules listed as dependencies in package.json . With the --production flag (or when the NODE_ENV environment variable is set to production ), npm will not install modules listed in devDependencies .

How do I force npm to install dependencies?

NPM installs devDependencies within the package. json file. The 'npm install' command should add all the dependencies and devDependencies automatically during installation. If you need to add specific devDependencies to your project, you can use this command- 'npm install --save-dev'.

Why is my npm install not working?

The Npm command not found error can appear when you install or upgrade npm. On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node. js installed, have an outdated version, or have permission issues.

Why do we not use -- save with npm install anymore?

You don't need --save anymore for NPM installs. This was long the golden standard to install a package and save it as a dependency in your project. Meaning if we didn't specify the --save flag, it would only get locally installed and not added to the package.


1 Answers

npm install without arguments installs all dependencies (and dev dependencies) listed in the package.json file.

npm install --production installs all the dependencies (but no dev dependency)

npm install <package> installs a package and its dependencies.

npm install <package> --save installs a package and its dependencies, and adds it in the package.json file.

Edit: Since npm 5, --save is implied.

like image 127
Iso Avatar answered Sep 20 '22 07:09

Iso