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
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)
What are your opinions comparing this method
npm install --only=prod
withnpm ci
?I found that
npm ci --only=prod
works as well (see link)You're correct.
npm ci
also installs dev dependencies.Adding
--only=prod
or--production
would not installdevDependencies
and just installdependencies
.I'll update the article to show both options 👍
It's now recommended to use
--omit=dev
over--production
😆 Good ole Node.js.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 thatnpm install
does when you have aNODE_ENV=production
environment variable set. So you can either set yourNODE_ENV
environment variable to production (recommended) or you could set this flag onnpm 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
andnpm ci --omit=dev
actually seem rather similar from what I could find. The only concern I would have withnpm ci --only=prod
is that it's not documented at all - onlynpm ci --include=prod
is, but that could be because the documentation has changed since this article/comment was posted!Anyways,
npm ci --omit=dev
preventsnpm ci
from installingdevDependencies
, however with this option thedevDependencies
are still included in the package-lock.json or npm-shrinkwrap.json files. This way, users can always manually install thedevDependencies
themselves later usingnpm ci --include=dev
if they wish to develop the project. (See this documentation for further information.