Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] npm ls --all --omit=dev includes dev dependencies of dependencies #7895

Closed
2 tasks done
hybridherbst opened this issue Nov 6, 2024 · 4 comments
Closed
2 tasks done
Labels
Bug thing that needs fixing Needs Triage needs review for next steps

Comments

@hybridherbst
Copy link

hybridherbst commented Nov 6, 2024

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

Current Behavior

Potentially related:

When using the --omit=dev flag, my expectation is that all dev dependencies are excluded. However, what seems to happen is that only the dev dependencies of the root package are excluded – dev dependencies of local dependency packages are still included. This is unexpected.

Expected Behavior

All devDependencies should be omitted when --omit=dev is used. Not just the devDependencies from the root package.

Steps To Reproduce

  1. Go to https://stackblitz.com/edit/vitejs-vite-jsxtyx?file=packages%2Fmy-package%2Fpackage.json&terminal=dev
  2. Run npm ls --all --omit=dev
  3. Note that typescript, a devDependency of a child package, is included in the list but shouldn't

Output:

❯ npm ls --all --omit=dev
[email protected] /home/projects/vitejs-vite-jsxtyx
`-- [email protected] -> ./packages/my-package
  `-- [email protected]

package.json of my-package:

{
  "name": "my-package",
  "version": "1.0.0",
  "displayName": "My Package",
  "devDependencies": {
    "typescript": "^5.6.3"
  }
}

Environment

  • npm: 10.8.2
  • Node.js: v20.9.0
  • OS Name: MacOS 15.1
  • System Model Name: Macbook Pro
  • npm config:
; "user" config from /Users/herbst/.npmrc
registry = "https://registry.npmjs.org"
; node bin location = /usr/local/bin/node
; node version = v20.9.0
; npm local prefix = /Users/herbst/git/...../js/package~
; npm version = 10.8.2
; cwd = /Users/herbst/git/....../js/package~
; HOME = /Users/herbst
; Run `npm config ls -l` to show all defaults.
@hybridherbst hybridherbst added Bug thing that needs fixing Needs Triage needs review for next steps labels Nov 6, 2024
@kchindam-infy
Copy link

@hybridherbst --omit=dev will not install dev dependencies on the file system but the dependencies will be still resolved. (Documentation npm ci --omit=dev )

@hybridherbst
Copy link
Author

hybridherbst commented Nov 6, 2024

@kchindam-infy the issue I opened is about the behaviour of npm ls, not about installation of dependencies. npm ls lists the existing dependencies of a package tree, and currently incorrectly only omits the devDependencies of the root package. The devDependencies of local dependencies are included despite --omit=dev, which I think is a bug.

@wraithgar
Copy link
Member

This is not a bug, it's a side effect of using linked dependencies. Normally the dev dependencies of your packages are not installed, so anything in the tree that exists under one of your dependencies is also a dependency.

Because you've linked in a package, that assumption breaks. This is just a side effect of using linked deps and it is not something we plan on changing.

@hybridherbst
Copy link
Author

I think this is very misleading, and there is no workaround to this bug.

If ls --all --omit=dev does not actually omit dev dependencies I'm not sure how this can be anything else but a bug.
Would I run ls --all --omit=dev in the linked dependency, it would exclude aka omit the dev dependencies. Just because I run it in the root package it does not omit the dev dependencies. Why would --omit=dev not also exclude the dev dependencies of linked packages?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps
Projects
None yet
Development

No branches or pull requests

3 participants