[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
- Create a project with a package.json like this:
{
"name": "npm-omit-optional-reproduction",
"private": true,
"version": "1.0.0",
"dependencies": {
"@stencil/core": "4.39.0"
}
}- Install dependencies:
npm install- Then run:
npm ls --omit=optional --alllThe 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:
npm ls --json --all --omit=optional- Then run a clean re-install with the
--omit=optionalflag set:
npm ci --omit=optional- Finally execute ls (
--omit=allis not needed):
npm ls --omit=optional --allThe 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:
; copy and paste output from `npm config ls` hereSource: npm/cli