"npm install package@version" unexpectedly installs all dev packages

What I Wanted to Do

Preconditions:

  • NPM version 6.4.1 is installed globally on a Windows 10 PC
  • A project containing a valid package.json and package-lock.json file
  • Package @angular/compiler-cli@7.2.5 is specified in the dev dependencies.
  • Production dependencies have been installed via npm ci --production

I want to install just one of my dev dependencies, e.g.:
npm install --no-save @angular/compiler-cli@7.2.5

What Happened Instead

The specified package is installed along with all of my dev dependencies. I didn’t expect the other dev dependencies to be installed.

Reproduction Steps

npm ci --production
npm install --no-save @angular/compiler-cli@7.2.5
npm list --depth=0

Note that other dev dependencies have been installed.

Also tested on other NPM versions using npx, with the same results:

npm ci --production
npx --ignore-existing npm@6.8.0 install --no-save @angular/compiler-cli@7.2.5
npm list --depth=0
npm ci --production
npx --ignore-existing npm@6.9.0 install --no-save @angular/compiler-cli@7.2.5
npm list --depth=0

Details

If I add the --no-package-lock flag, and specify exactly the desired version, then I get the expected behavior, e.g.:
npm install --no-save --no-package-lock @angular/compiler-cli@7.2.5

Platform Info

$ npm --versions
{ ___redacted___: '0.0.0',
  npm: '6.4.1',
  ares: '1.14.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.13.0',
  openssl: '1.1.0i',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '6.8.275.32-node.36',
  zlib: '1.2.11' }

$ node -p process.platform
win32

(Nice use of npx in reproduction steps. :slight_smile: )

1 Like

Might be related to https://github.com/npm/npm/issues/17669

I was wondering if this was intentional… It’s not really what I was expecting, or desired, but admittedly, my situation is probably a corner case.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.