npm / npm/cli

[BUG] Dependency hoisting in workspaces not working, depending on workspace name

Open
#4,512 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Documentation Priority 2 Release 8.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

If a workspace folder has the same name as one of its direct dependencies, that dependency will not be hoisted to the project root on install.

Note that behavior only applies for top-level dependencies. Nested dependencies will still be hoisted properly.

Expected Behavior

The dependency should be hoisted to the root.

I'm not entirely sure whether this is actually a bug or a constraint due to the Node module resolution algorithm or something similar. However, I have not found any official or inofficial documentation of this behavior. If the behavior is by design, this issue could at least serve as an anchor for other users who run into the same problem.

Steps To Reproduce

Follow the steps in the reproduction repository I made: loilo/repro-npm-workspaces-hoisting.

Environment
  • npm: 8.5.3
  • Node.js: 17.6.0
  • OS Name: macOS 12.2.1
  • System Model Name: MacBook Pro
  • npm config:
; "builtin" config from /usr/local/lib/node_modules/npm/npmrc

prefix = "/usr/local" 

; "user" config from /Users/florian/.npmrc

//localhost:4873/:_authToken = (protected) 
//registry.npmjs.org/:_authToken = (protected) 
http://localhost:4873 = "" 

; node bin location = /usr/local/Cellar/node/17.6.0_1/bin/node
; cwd = /Volumes/RAMDisk/repro-npm-workspaces-hoisting
; HOME = /Users/florian
; 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

Start by running the steps in the loilo/repro-npm-workspaces-hoisting repository against the npm CLI and inspect the workspace dependency-hoisting behavior. Done means resolving the workspace-name collision while still hoisting the direct dependency to the project root, or documenting that the behavior is required by Node.js module resolution.

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.