#9962·npm

[BUG] Inconsistent behavior of `--omit=optional` in `npm i` and `npm ls`

Author: philSixZeroCreated Sep 11, 2026Updated Sep 29, 2026
LabelsBugPriority 3

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

This is not just a request to bump a dependency for a CVE

  • This is not solely a request to bump a dependency for a CVE

Current Behavior

npm ls --omit=optional --all continues to include optional dependencies in its output.

However, npm ls --omit=dev --all excludes all development-only dependencies.

Additionally, npm i --omit=optional excludes all optional dependencies from being installed (docs).

Expected Behavior

When --omit=optional is supplied to npm ls, optional dependency entries should be excluded from the reported dependency tree, just like --omit=dev consistently excludes development-only dependency roots from the output and npm i --omit=optional does not install optional dependencies.

Steps To Reproduce

  1. Create a project with a package.json like this:
json
{
  "name": "npm-omit-optional-reproduction",
  "private": true,
  "version": "1.0.0",
  "dependencies": {
    "@stencil/core": "4.39.0"
  }
}
  1. Install dependencies:
bash
npm install
  1. Then run:
bash
npm ls --omit=optional --alll

The output includes optional dependencies:

└─┬ @stencil/[email protected]
  ├── @rollup/[email protected]
  ├── UNMET OPTIONAL DEPENDENCY @rollup/[email protected]
  ├── UNMET OPTIONAL DEPENDENCY @rollup/[email protected]
  ├── UNMET OPTIONAL DEPENDENCY @rollup/[email protected]
  ├── UNMET OPTIONAL DEPENDENCY @rollup/[email protected]
  ├── UNMET OPTIONAL DEPENDENCY @rollup/[email protected]
  ├── UNMET OPTIONAL DEPENDENCY @rollup/[email protected]
  └── UNMET OPTIONAL DEPENDENCY @rollup/[email protected]

The same behavior is visible in JSON output:

bash
npm ls --json --all --omit=optional
  1. Then run a clean re-install with the --omit=optional flag set:
bash
npm ci --omit=optional
  1. Finally execute ls (--omit=all is not needed):
bash
npm ls --omit=optional --all

The output doesn't include any optional dependency:

└──  @stencil/[email protected]

Environment

  • npm: 12.0.1
  • Node.js: v24.18.0
  • OS Name: macOS arm64
  • System Model Name:
  • npm config:
ini
; copy and paste output from `npm config ls` here