npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

npm list reports errors for dependencies of optional dependencies that are not installed

What I Wanted to Do

Execute “npm list” without errors on a valid install.

What Happened Instead

With npm 6.5.0, npm list is reporting errors for dependencies of optional dependencies that are not installed. Looking at the history of package-lock.json from the project that identified this error, with the last package changes that I made to the project, in addition to adding/removed packages as intended, the “optional” attribute was also removed from the dependencies of optional dependencies. If I reverse those changes (i.e. add back the optional attributes) and re-install the errors go away, but with any package changes package-lock.json gets updated again to remove them.

This appears to be related to the fix for https://github.com/npm/cli/pull/76.

Reproduction Steps

In a new directory, perform npm install with the following package.json file on Windows or Linux. Gulp 4 has an optional dependency on the fsevents package, which is Mac-specific, so it will not be installed.

{
  "name": "something",
  "version": "1.0.0",
  "description": "something",
  "author": "",
  "license": "MIT",
  "devDependencies": {
    "gulp": "^4.0.0"
  }
}

Perform an npm list and the following errors are seen:

npm ERR! missing: safe-buffer@5.1.2, required by readable-stream@2.3.6
npm ERR! missing: safe-buffer@5.1.2, required by string_decoder@1.1.1
npm ERR! missing: strip-ansi@3.0.1, required by gauge@2.7.4
npm ERR! missing: strip-ansi@3.0.1, required by string-width@1.0.2
npm ERR! missing: ansi-regex@2.1.1, required by strip-ansi@3.0.1
npm ERR! missing: wrappy@1.0.2, required by inflight@1.0.6
npm ERR! missing: wrappy@1.0.2, required by once@1.4.0
npm ERR! missing: safe-buffer@5.1.2, required by tar@4.4.8
npm ERR! missing: yallist@3.0.3, required by tar@4.4.8
npm ERR! missing: safe-buffer@5.1.2, required by minipass@2.3.5
npm ERR! missing: yallist@3.0.3, required by minipass@2.3.5

Looking at the list output, the errors are all dependencies of optional dependencies:

  | | +-- UNMET OPTIONAL DEPENDENCY fsevents@1.2.7
  | | | +-- UNMET OPTIONAL DEPENDENCY nan@2.12.1
  | | | `-- UNMET OPTIONAL DEPENDENCY node-pre-gyp@0.10.3
  | | |   +-- UNMET OPTIONAL DEPENDENCY detect-libc@1.0.3
  | | |   +-- UNMET OPTIONAL DEPENDENCY mkdirp@0.5.1
  | | |   | `-- UNMET OPTIONAL DEPENDENCY minimist@0.0.8
  | | |   +-- UNMET OPTIONAL DEPENDENCY needle@2.2.4
  | | |   | +-- UNMET OPTIONAL DEPENDENCY debug@2.6.9
  | | |   | | `-- UNMET OPTIONAL DEPENDENCY ms@2.0.0
  | | |   | +-- UNMET OPTIONAL DEPENDENCY iconv-lite@0.4.24
  | | |   | | `-- UNMET OPTIONAL DEPENDENCY safer-buffer@2.1.2
  | | |   | `-- UNMET OPTIONAL DEPENDENCY sax@1.2.4
  | | |   +-- UNMET OPTIONAL DEPENDENCY nopt@4.0.1
  | | |   | +-- UNMET OPTIONAL DEPENDENCY abbrev@1.1.1
  | | |   | `-- UNMET OPTIONAL DEPENDENCY osenv@0.1.5
  | | |   |   +-- UNMET OPTIONAL DEPENDENCY os-homedir@1.0.2
  | | |   |   `-- UNMET OPTIONAL DEPENDENCY os-tmpdir@1.0.2
  | | |   +-- UNMET OPTIONAL DEPENDENCY npm-packlist@1.2.0
  | | |   | +-- UNMET OPTIONAL DEPENDENCY ignore-walk@3.0.1
  | | |   | | `-- UNMET OPTIONAL DEPENDENCY minimatch@3.0.4
  | | |   | |   `-- UNMET OPTIONAL DEPENDENCY brace-expansion@1.1.11
  | | |   | |     +-- UNMET OPTIONAL DEPENDENCY balanced-match@1.0.0
  | | |   | |     `-- UNMET OPTIONAL DEPENDENCY concat-map@0.0.1
  | | |   | `-- UNMET OPTIONAL DEPENDENCY npm-bundled@1.0.5
  | | |   +-- UNMET OPTIONAL DEPENDENCY npmlog@4.1.2
  | | |   | +-- UNMET OPTIONAL DEPENDENCY are-we-there-yet@1.1.5
  | | |   | | +-- UNMET OPTIONAL DEPENDENCY delegates@1.0.0
  | | |   | | `-- UNMET OPTIONAL DEPENDENCY readable-stream@2.3.6
  | | |   | |   +-- UNMET OPTIONAL DEPENDENCY core-util-is@1.0.2
  | | |   | |   +-- UNMET OPTIONAL DEPENDENCY inherits@2.0.3
  | | |   | |   +-- UNMET OPTIONAL DEPENDENCY isarray@1.0.0
  | | |   | |   +-- UNMET OPTIONAL DEPENDENCY process-nextick-args@2.0.0
  | | |   | |   +-- UNMET DEPENDENCY safe-buffer@5.1.2
  | | |   | |   +-- UNMET OPTIONAL DEPENDENCY string_decoder@1.1.1
  | | |   | |   | `-- UNMET DEPENDENCY safe-buffer@5.1.2
  | | |   | |   `-- UNMET OPTIONAL DEPENDENCY util-deprecate@1.0.2
  | | |   | +-- UNMET OPTIONAL DEPENDENCY console-control-strings@1.1.0
  | | |   | +-- UNMET OPTIONAL DEPENDENCY gauge@2.7.4
  | | |   | | +-- UNMET OPTIONAL DEPENDENCY aproba@1.2.0
  | | |   | | +-- UNMET OPTIONAL DEPENDENCY console-control-strings@1.1.0
  | | |   | | +-- UNMET OPTIONAL DEPENDENCY has-unicode@2.0.1
  | | |   | | +-- UNMET OPTIONAL DEPENDENCY object-assign@4.1.1
  | | |   | | +-- UNMET OPTIONAL DEPENDENCY signal-exit@3.0.2
  | | |   | | +-- UNMET OPTIONAL DEPENDENCY string-width@1.0.2
  | | |   | | | +-- UNMET OPTIONAL DEPENDENCY code-point-at@1.1.0
  | | |   | | | +-- UNMET OPTIONAL DEPENDENCY is-fullwidth-code-point@1.0.0
  | | |   | | | | `-- UNMET OPTIONAL DEPENDENCY number-is-nan@1.0.1
  | | |   | | | `-- UNMET DEPENDENCY strip-ansi@3.0.1
  | | |   | | +-- UNMET DEPENDENCY strip-ansi@3.0.1
  | | |   | | | `-- UNMET DEPENDENCY ansi-regex@2.1.1
  | | |   | | `-- UNMET OPTIONAL DEPENDENCY wide-align@1.1.3
  | | |   | |   `-- UNMET OPTIONAL DEPENDENCY string-width@1.0.2
  | | |   | `-- UNMET OPTIONAL DEPENDENCY set-blocking@2.0.0
  | | |   +-- UNMET OPTIONAL DEPENDENCY rc@1.2.8
  | | |   | +-- UNMET OPTIONAL DEPENDENCY deep-extend@0.6.0
  | | |   | +-- UNMET OPTIONAL DEPENDENCY ini@1.3.5
  | | |   | +-- UNMET OPTIONAL DEPENDENCY minimist@1.2.0
  | | |   | `-- UNMET OPTIONAL DEPENDENCY strip-json-comments@2.0.1
  | | |   +-- UNMET OPTIONAL DEPENDENCY rimraf@2.6.3
  | | |   | `-- UNMET OPTIONAL DEPENDENCY glob@7.1.3
  | | |   |   +-- UNMET OPTIONAL DEPENDENCY fs.realpath@1.0.0
  | | |   |   +-- UNMET OPTIONAL DEPENDENCY inflight@1.0.6
  | | |   |   | +-- UNMET OPTIONAL DEPENDENCY once@1.4.0
  | | |   |   | `-- UNMET DEPENDENCY wrappy@1.0.2
  | | |   |   +-- UNMET OPTIONAL DEPENDENCY inherits@2.0.3
  | | |   |   +-- UNMET OPTIONAL DEPENDENCY minimatch@3.0.4
  | | |   |   +-- UNMET OPTIONAL DEPENDENCY once@1.4.0
  | | |   |   | `-- UNMET DEPENDENCY wrappy@1.0.2
  | | |   |   `-- UNMET OPTIONAL DEPENDENCY path-is-absolute@1.0.1
  | | |   +-- UNMET OPTIONAL DEPENDENCY semver@5.6.0
  | | |   `-- UNMET OPTIONAL DEPENDENCY tar@4.4.8
  | | |     +-- UNMET OPTIONAL DEPENDENCY chownr@1.1.1
  | | |     +-- UNMET OPTIONAL DEPENDENCY fs-minipass@1.2.5
  | | |     | `-- UNMET OPTIONAL DEPENDENCY minipass@2.3.5
  | | |     +-- UNMET OPTIONAL DEPENDENCY minipass@2.3.5
  | | |     | +-- UNMET DEPENDENCY safe-buffer@5.1.2
  | | |     | `-- UNMET DEPENDENCY yallist@3.0.3
  | | |     +-- UNMET OPTIONAL DEPENDENCY minizlib@1.2.1
  | | |     | `-- UNMET OPTIONAL DEPENDENCY minipass@2.3.5
  | | |     +-- UNMET OPTIONAL DEPENDENCY mkdirp@0.5.1
  | | |     +-- UNMET DEPENDENCY safe-buffer@5.1.2
  | | |     `-- UNMET DEPENDENCY yallist@3.0.3

Looking at package-lock.json, these sub-dependencies are flagged as optional.

Platform Info

$ npm --versions
{ something: '1.0.0',
  npm: '6.5.0',
  ares: '1.15.0',
  brotli: '1.0.7',
  cldr: '34.0',
  http_parser: '2.8.0',
  icu: '63.1',
  llhttp: '1.0.1',
  modules: '67',
  napi: '3',
  nghttp2: '1.34.0',
  node: '11.7.0',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.24.1',
  v8: '7.0.276.38-node.16',
  zlib: '1.2.11' }
$ node -p process.platform
win32
(also occurs in a node:latest container)


That PR was only merged in the 6.6.0 release (and respective prereleases), not yet in 6.5.0. Installing with 6.6.0 I get this list (with no UNMET DEPENDENCY):

  │ │ ├─┬ UNMET OPTIONAL DEPENDENCY fsevents@1.2.7
  │ │ │ ├── UNMET OPTIONAL DEPENDENCY nan@2.12.1
  │ │ │ └─┬ UNMET OPTIONAL DEPENDENCY node-pre-gyp@0.10.3
  │ │ │   ├── UNMET OPTIONAL DEPENDENCY detect-libc@1.0.3
  │ │ │   ├─┬ UNMET OPTIONAL DEPENDENCY mkdirp@0.5.1
  │ │ │   │ └── UNMET OPTIONAL DEPENDENCY minimist@0.0.8
  │ │ │   ├─┬ UNMET OPTIONAL DEPENDENCY needle@2.2.4
  │ │ │   │ ├─┬ UNMET OPTIONAL DEPENDENCY debug@2.6.9
  │ │ │   │ │ └── UNMET OPTIONAL DEPENDENCY ms@2.0.0
  │ │ │   │ ├─┬ UNMET OPTIONAL DEPENDENCY iconv-lite@0.4.24
  │ │ │   │ │ └── UNMET OPTIONAL DEPENDENCY safer-buffer@2.1.2
  │ │ │   │ └── UNMET OPTIONAL DEPENDENCY sax@1.2.4
  │ │ │   ├─┬ UNMET OPTIONAL DEPENDENCY nopt@4.0.1
  │ │ │   │ ├── UNMET OPTIONAL DEPENDENCY abbrev@1.1.1
  │ │ │   │ └─┬ UNMET OPTIONAL DEPENDENCY osenv@0.1.5
  │ │ │   │   ├── UNMET OPTIONAL DEPENDENCY os-homedir@1.0.2
  │ │ │   │   └── UNMET OPTIONAL DEPENDENCY os-tmpdir@1.0.2
  │ │ │   ├─┬ UNMET OPTIONAL DEPENDENCY npm-packlist@1.2.0
  │ │ │   │ ├─┬ UNMET OPTIONAL DEPENDENCY ignore-walk@3.0.1
  │ │ │   │ │ └─┬ UNMET OPTIONAL DEPENDENCY minimatch@3.0.4
  │ │ │   │ │   └─┬ UNMET OPTIONAL DEPENDENCY brace-expansion@1.1.11
  │ │ │   │ │     ├── UNMET OPTIONAL DEPENDENCY balanced-match@1.0.0
  │ │ │   │ │     └── UNMET OPTIONAL DEPENDENCY concat-map@0.0.1
  │ │ │   │ └── UNMET OPTIONAL DEPENDENCY npm-bundled@1.0.5
  │ │ │   ├─┬ UNMET OPTIONAL DEPENDENCY npmlog@4.1.2
  │ │ │   │ ├─┬ UNMET OPTIONAL DEPENDENCY are-we-there-yet@1.1.5
  │ │ │   │ │ ├── UNMET OPTIONAL DEPENDENCY delegates@1.0.0
  │ │ │   │ │ └─┬ UNMET OPTIONAL DEPENDENCY readable-stream@2.3.6
  │ │ │   │ │   ├── UNMET OPTIONAL DEPENDENCY core-util-is@1.0.2
  │ │ │   │ │   ├── UNMET OPTIONAL DEPENDENCY inherits@2.0.3
  │ │ │   │ │   ├── UNMET OPTIONAL DEPENDENCY isarray@1.0.0
  │ │ │   │ │   ├── UNMET OPTIONAL DEPENDENCY process-nextick-args@2.0.0
  │ │ │   │ │   ├── UNMET OPTIONAL DEPENDENCY safe-buffer@5.1.2
  │ │ │   │ │   ├─┬ UNMET OPTIONAL DEPENDENCY string_decoder@1.1.1
  │ │ │   │ │   │ └── UNMET OPTIONAL DEPENDENCY safe-buffer@5.1.2
  │ │ │   │ │   └── UNMET OPTIONAL DEPENDENCY util-deprecate@1.0.2
  │ │ │   │ ├── UNMET OPTIONAL DEPENDENCY console-control-strings@1.1.0
  │ │ │   │ ├─┬ UNMET OPTIONAL DEPENDENCY gauge@2.7.4
  │ │ │   │ │ ├── UNMET OPTIONAL DEPENDENCY aproba@1.2.0
  │ │ │   │ │ ├── UNMET OPTIONAL DEPENDENCY console-control-strings@1.1.0
  │ │ │   │ │ ├── UNMET OPTIONAL DEPENDENCY has-unicode@2.0.1
  │ │ │   │ │ ├── UNMET OPTIONAL DEPENDENCY object-assign@4.1.1
  │ │ │   │ │ ├── UNMET OPTIONAL DEPENDENCY signal-exit@3.0.2
  │ │ │   │ │ ├─┬ UNMET OPTIONAL DEPENDENCY string-width@1.0.2
  │ │ │   │ │ │ ├── UNMET OPTIONAL DEPENDENCY code-point-at@1.1.0
  │ │ │   │ │ │ ├─┬ UNMET OPTIONAL DEPENDENCY is-fullwidth-code-point@1.0.0
  │ │ │   │ │ │ │ └── UNMET OPTIONAL DEPENDENCY number-is-nan@1.0.1
  │ │ │   │ │ │ └── UNMET OPTIONAL DEPENDENCY strip-ansi@3.0.1
  │ │ │   │ │ ├─┬ UNMET OPTIONAL DEPENDENCY strip-ansi@3.0.1
  │ │ │   │ │ │ └── UNMET OPTIONAL DEPENDENCY ansi-regex@2.1.1
  │ │ │   │ │ └─┬ UNMET OPTIONAL DEPENDENCY wide-align@1.1.3
  │ │ │   │ │   └── UNMET OPTIONAL DEPENDENCY string-width@1.0.2
  │ │ │   │ └── UNMET OPTIONAL DEPENDENCY set-blocking@2.0.0
  │ │ │   ├─┬ UNMET OPTIONAL DEPENDENCY rc@1.2.8
  │ │ │   │ ├── UNMET OPTIONAL DEPENDENCY deep-extend@0.6.0
  │ │ │   │ ├── UNMET OPTIONAL DEPENDENCY ini@1.3.5
  │ │ │   │ ├── UNMET OPTIONAL DEPENDENCY minimist@1.2.0
  │ │ │   │ └── UNMET OPTIONAL DEPENDENCY strip-json-comments@2.0.1
  │ │ │   ├─┬ UNMET OPTIONAL DEPENDENCY rimraf@2.6.3
  │ │ │   │ └─┬ UNMET OPTIONAL DEPENDENCY glob@7.1.3
  │ │ │   │   ├── UNMET OPTIONAL DEPENDENCY fs.realpath@1.0.0
  │ │ │   │   ├─┬ UNMET OPTIONAL DEPENDENCY inflight@1.0.6
  │ │ │   │   │ ├── UNMET OPTIONAL DEPENDENCY once@1.4.0
  │ │ │   │   │ └── UNMET OPTIONAL DEPENDENCY wrappy@1.0.2
  │ │ │   │   ├── UNMET OPTIONAL DEPENDENCY inherits@2.0.3
  │ │ │   │   ├── UNMET OPTIONAL DEPENDENCY minimatch@3.0.4
  │ │ │   │   ├─┬ UNMET OPTIONAL DEPENDENCY once@1.4.0
  │ │ │   │   │ └── UNMET OPTIONAL DEPENDENCY wrappy@1.0.2
  │ │ │   │   └── UNMET OPTIONAL DEPENDENCY path-is-absolute@1.0.1
  │ │ │   ├── UNMET OPTIONAL DEPENDENCY semver@5.6.0
  │ │ │   └─┬ UNMET OPTIONAL DEPENDENCY tar@4.4.8
  │ │ │     ├── UNMET OPTIONAL DEPENDENCY chownr@1.1.1
  │ │ │     ├─┬ UNMET OPTIONAL DEPENDENCY fs-minipass@1.2.5
  │ │ │     │ └── UNMET OPTIONAL DEPENDENCY minipass@2.3.5
  │ │ │     ├─┬ UNMET OPTIONAL DEPENDENCY minipass@2.3.5
  │ │ │     │ ├── UNMET OPTIONAL DEPENDENCY safe-buffer@5.1.2
  │ │ │     │ └── UNMET OPTIONAL DEPENDENCY yallist@3.0.3
  │ │ │     ├─┬ UNMET OPTIONAL DEPENDENCY minizlib@1.2.1
  │ │ │     │ └── UNMET OPTIONAL DEPENDENCY minipass@2.3.5
  │ │ │     ├── UNMET OPTIONAL DEPENDENCY mkdirp@0.5.1
  │ │ │     ├── UNMET OPTIONAL DEPENDENCY safe-buffer@5.1.2
  │ │ │     └── UNMET OPTIONAL DEPENDENCY yallist@3.0.3