cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] npm ci --omit=dev does not omit dev deps

Open lemoustachiste opened this issue 7 months ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

I am installing in a Docker container with npm ci --omit=dev.

I have also tried to set the NODE_ENV to production as I saw this on stackoverflow, to no avail. I have read the various similar reports of this issue but nothing worked in my case.

Here is the failure when running docker build:

3.497 npm ERR! code ERESOLVE
3.503 npm ERR! ERESOLVE could not resolve
3.503 npm ERR!
3.503 npm ERR! While resolving: [email protected]
3.503 npm ERR! Found: [email protected]
3.504 npm ERR! node_modules/eslint-plugin-n
3.504 npm ERR!   dev eslint-plugin-n@"^16.5.0" from the root project
3.504 npm ERR!   peer eslint-plugin-n@"^15.0.0 || ^16.0.0 " from [email protected]
3.504 npm ERR!   node_modules/eslint-config-standard
3.504 npm ERR!     dev eslint-config-standard@"^17.1.0" from the root project
3.504 npm ERR!     peer eslint-config-standard@"^17.0.0" from [email protected]
3.504 npm ERR!     node_modules/eslint-config-semistandard
3.504 npm ERR!       dev eslint-config-semistandard@"^17.0.0" from the root project
3.504 npm ERR!     1 more (eslint-config-standard-with-typescript)
3.504 npm ERR!   1 more (eslint-config-standard-with-typescript)
3.504 npm ERR!
3.505 npm ERR! Could not resolve dependency:
3.505 npm ERR! peer eslint-plugin-n@"^15.0.0" from [email protected]
3.505 npm ERR! node_modules/eslint-config-semistandard
3.505 npm ERR!   dev eslint-config-semistandard@"^17.0.0" from the root project
3.505 npm ERR!
3.505 npm ERR! Conflicting peer dependency: [email protected]
3.505 npm ERR! node_modules/eslint-plugin-n
3.505 npm ERR!   peer eslint-plugin-n@"^15.0.0" from [email protected]
3.505 npm ERR!   node_modules/eslint-config-semistandard
3.505 npm ERR!     dev eslint-config-semistandard@"^17.0.0" from the root project
3.505 npm ERR!
3.505 npm ERR! Fix the upstream dependency conflict, or retry
3.505 npm ERR! this command with --force or --legacy-peer-deps
3.505 npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
3.505 npm ERR!
3.505 npm ERR!
3.505 npm ERR! For a full report see:
3.505 npm ERR! /root/.npm/_logs/2023-12-20T16_44_28_598Z-eresolve-report.txt

My Dockerfile instruction:

COPY package*.json ./


ENV NODE_ENV=production
RUN npm ci --omit=dev

npm explain eslint-config-semistandard:

[email protected] dev
node_modules/eslint-config-semistandard
  dev eslint-config-semistandard@"^17.0.0" from the root project

npm explain eslint-plugin-n:

[email protected] dev
node_modules/eslint-plugin-n
  dev eslint-plugin-n@"^16.5.0" from the root project

and FWIW npm list eslint-plugin-n

npm ERR! code ELSPROBLEMS
npm ERR! invalid: [email protected] /Users/julien/work/cvjs-docker/node_modules/eslint-plugin-n
@blockcerts/[email protected] /Users/julien/work/cvjs-docker
├─┬ [email protected]
│ └── [email protected] deduped invalid: "^15.0.0" from node_modules/eslint-config-semistandard
├─┬ [email protected]
│ └── [email protected] deduped invalid: "^15.0.0" from node_modules/eslint-config-semistandard
├─┬ [email protected]
│ └── [email protected] deduped invalid: "^15.0.0" from node_modules/eslint-config-semistandard
└── [email protected] invalid: "^15.0.0" from node_modules/eslint-config-semistandard

Expected Behavior

So by all accounts it should not be a problem when using --omit=dev, as the dev dependencies shouldn't even be installed.

I'm at a loss, and overall I do not wish to install dev deps at all as this will be a production build.

Thanks for your help

Steps To Reproduce

  1. See this branch: https://github.com/blockchain-certificates/cvjs-docker/tree/chore/eslint
  2. Have Docker on your machine and start the engine
  3. npm install, then npm run build
  4. See the log from the Docker output

Environment

  • npm: 10.2.3
  • Node.js: 18.19.0
  • OS Name: Docker
  • System Model Name:
  • npm config:
#8 0.841 ; node bin location = /usr/local/bin/node
#8 0.841 ; node version = v18.19.0
#8 0.841 ; npm local prefix = /usr/src/app
#8 0.841 ; npm version = 10.2.3
#8 0.841 ; cwd = /usr/src/app
#8 0.841 ; HOME = /root

lemoustachiste avatar Dec 20 '23 17:12 lemoustachiste

Workaround I've been using. Just make sure to double check your node_modules before sending this off to production

RUN npm ls --depth=0 --omit=dev | sed -n '1!p' | cut -d ' ' -f 2 >> deps.txt
RUN cat deps.txt | while read line; do npm install $line; done

Gum-Christopher-bah avatar Mar 28 '24 15:03 Gum-Christopher-bah

@lemoustachiste --omit=dev will not install dev dependencies on the file system but the dependencies will be still resolved. (Documentation npm ci --omit=dev ) While resolving those dependencies, I see the peer dependency conflicts errors are being thrown when running. You can try resolving those conflicts and then check.

milaninfy avatar Apr 29 '24 20:04 milaninfy