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


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?

4/16/2016 4:16:39 AM

Accepted Answer

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: Before v3.3.0 of npm (2015-08-13), the option was called --production, i.e. npm install --production.

9/4/2018 2:22:05 PM

I run into that problem too! npm install is somewhat confusing and web posts keep bringing in the -d/--dev flags as if there is an explicit 'development' install mode.

  • npm install will install both "dependencies" and "devDependencies"

  • npm install --production will only install "dependencies"

  • npm install --dev will only install "devDependencies"

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow