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=prodwithnpm ci?I found that
npm ci --only=prodworks as well (see link)You're correct.
npm cialso installs dev dependencies.Adding
--only=prodor--productionwould not installdevDependenciesand just installdependencies.I'll update the article to show both options π
It's now recommended to use
--omit=devover--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 --productionexhibits the same behavior thatnpm installdoes when you have aNODE_ENV=productionenvironment variable set. So you can either set yourNODE_ENVenvironment 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=prodandnpm ci --omit=devactually seem rather similar from what I could find. The only concern I would have withnpm ci --only=prodis that it's not documented at all - onlynpm ci --include=prodis, but that could be because the documentation has changed since this article/comment was posted!Anyways,
npm ci --omit=devpreventsnpm cifrom installingdevDependencies, however with this option thedevDependenciesare still included in the package-lock.json or npm-shrinkwrap.json files. This way, users can always manually install thedevDependenciesthemselves later usingnpm ci --include=devif they wish to develop the project. (See this documentation for further information.