Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you prevent install of "devDependencies" NPM modules for Node.js (package.json)?

Tags:

node.js

npm

I have this in my package.json file (shortened version):

{   "name": "a-module",   "version": "0.0.1",   "dependencies": {     "coffee-script":      ">= 1.1.3"   },   "devDependencies": {     "stylus":             ">= 0.17.0"   } } 

I am using NPM version 1.1.1 on Mac 10.6.8.

When I run the following command from the project root, it installs both the dependencies and devDependencies:

npm install 

I was under the impression that this command installed the devDependencies:

npm install --dev 

How do I make it so npm install only installs dependencies (so production environment only gets those modules), while something like npm install --dev installs both dependencies and devDependencies?

like image 988
Lance Avatar asked Feb 13 '12 21:02

Lance


People also ask

How do I prevent npm install from removing packages?

To Save : npm install --save {package_name} . This will save the package to package. json and install using npm install . You can't particularly control the dependencies(fully).

Does npm install installs devDependencies?

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 .

What is the use of devDependencies in package json?

Dev Dependencies: In package. json file, there is an object called as dev Dependencies and it consists of all the packages that are used in the project in its development phase and not in the production or testing environment with its version number.


1 Answers

The npm install command will install the devDependencies along other dependencies when run inside a package directory, in a development environment (the default).

Use npm install --only=prod (or --only=production) to install only dependencies, and not devDependencies, regardless of the value of the NODE_ENV environment variable.

Source: npm docs

Note: you may also need --no-optional

Note: Before v3.3.0 of npm (2015-08-13), the option was called --production, i.e. npm install --production.

like image 112
Rohan Singh Avatar answered Sep 23 '22 08:09

Rohan Singh