npm / npm/cli

--install-strategy=nested still hoists workspace packages

Open
#6,537 18 comments 35 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 9.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

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

Currently, running npm install at the root of a monorepo using npm workspaces with the '--install-strategy=nested' flag almost does what I would expect it to do - it puts all the dependencies in separate node_modules folders for each package, but it still puts the symlinks to the local monorepo packages at the root.

Expected Behavior

I would expect the symlinks to the monorepo packages to be inserted into the nested node_modules folders rather than the root (and only for the packages that depend on them).

I also noticed that the --omit=dev flag seems to not work in this use case - note in the linked repro repo running 'npm install --install-strategy=nested --omit=dev' still results in eslint being added to workspace2's node_modules folder, even though it's only a devDependency. (I can make a separate issue for this if that would be better?)

Note for context: My use case here is a monorepo with multiple node apps in it, each of which needs to be separately bundled into a docker image with only it's dependencies, I don't want to unnecessarily include the dependencies of other packages in the monorepo. The '--install-strategy=nested' flag seems like what I need for my use case, but the current behaviour doesn't quite work.

Steps To Reproduce
  • make sure you have npm 9.7.1
  • clone this repo: https://github.com/pcone/npmissuerepro
  • run 'npm install --install-strategy=nested --omit=dev' at the root
  • note that a node_modules folder is still created at the root
  • note that the nested node_modules folder for workspace1 does not contain a symlink to workspace2, despite it being a dependency
  • note that eslint is still installed, despite being a dev dependency
Environment
  • npm: 9.7.1
  • Node.js: 16.16.0
  • OS Name: Windows 10 22H2
  • npm config:
; "user" config from C:\Users\<redacted>\.npmrc

<redacted internal repo>:_password = (protected)
<redacted internal repo>:email = "not-used@example.com"
<redacted internal repo>:username = <redacted>

; node bin location = C:\Program Files\nodejs\node.exe
; node version = v16.16.0
; npm local prefix = C:\S
; npm version = 9.7.1
; cwd = C:\S\npmrepro
; HOME = C:\Users\<redacted>
; Run `npm config ls -l` to show all defaults.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Clone the linked npmissuerepro repository and run npm install --install-strategy=nested --omit=dev from its root with npm 9.7.1. Inspect the resulting root and workspace node_modules folders; done means workspace links appear only for dependent packages in their nested folders and devDependencies such as eslint are omitted.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.