DEV Community

Dana Woodman
Dana Woodman

Posted on • Edited on

Include (or omit) Node.js devDependencies in your CI environment

UPDATE: It's actually simpler to use npm ci instead of npm install because it installs devDependencies too and is actually more efficient. Hat tip to Lucian 🍻

Ever need to install your devDependencies in a CI environment but the environment wants to install only dependencies? Here's how to fix it:

npm install --include=dev
Enter fullscreen mode Exit fullscreen mode

You can also omit dependencies with the --omit=... flag.

You can use the options dev, optional and peer in both these flags.

Hope that saves you a few minutes, as it did me! 🍻

Hat tip to Ben McCann on the Svelte Discord for pointing me in the right direction!


Follow me on Dev.to, Twitter and Github for more web dev and startup related content 🤓

Top comments (4)

Collapse
 
lil5 profile image
Lucian I. Last • Edited

What are your opinions comparing this method npm install --only=prod with npm ci?

I found that npm ci --only=prod works as well (see link)

Collapse
 
danawoodman profile image
Dana Woodman

You're correct. npm ci also installs dev dependencies.

Adding --only=prod or --production would not install devDependencies and just install dependencies.

I'll update the article to show both options 👍

Collapse
 
jef profile image
Jef LeCompte

It's now recommended to use --omit=dev over --production 😆 Good ole Node.js.

Collapse
 
bjf5201 profile image
Bethany Fannin

For a lil more background, there is a difference between the behaviors of npm install --production, npm ci --only=prod, and --npm ci omit=dev:

npm install --production exhibits the same behavior that npm install does when you have a NODE_ENV=production environment variable set. So you can either set your NODE_ENV environment variable to production (recommended) or you could set this flag on npm install (or both to ensure that you get the behavior you want just in case something goes wrong with the environment variable!).

npm ci --only=prod and npm ci --omit=dev actually seem rather similar from what I could find. The only concern I would have with npm ci --only=prod is that it's not documented at all - only npm ci --include=prod is, but that could be because the documentation has changed since this article/comment was posted!

Anyways, npm ci --omit=dev prevents npm ci from installing devDependencies, however with this option the devDependencies are still included in the package-lock.json or npm-shrinkwrap.json files. This way, users can always manually install the devDependencies themselves later using npm ci --include=dev if they wish to develop the project. (See this documentation for further information.