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

Solution 1:

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.

Solution 2:

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"

Solution 3:

The new option is:

npm install --only=prod

If you want to install only devDependencies:

npm install --only=dev