npm / npm/cli

[BUG] Aliases of NPM packages are broken when used in dependencies

Open
#4,197 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug config:aliases Priority 2
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

Dependencies in the following package.json file are not resolved correctly:

{
  "dependencies": {
    "once": "^1.4.0",
    "pikchr-wasm": "^1.0.1"
  }
}

This is installed:

├─┬ once@1.4.0
│ └── wrappy@1.0.2
└─┬ pikchr-wasm@1.0.1
  └── once@1.4.0 deduped
Expected Behavior

Notice how the wrong once module got installed for pikchr-wasm, it's dependency tree should look like this:

pikchr-wasm@1.0.1
└── once@npm:@fabiospampinato/once@1.0.0

I guess the problem is that NPM got confused since I'm using an alias for a module, and that alias is the name of another module that the parent package needs.

Steps To Reproduce

Run npm i on that package.json.

Environment
  • npm: 8.3.0
  • Node: 17.3.0
  • OS: macOS 12.1
  • platform: arm64
  • npm config:
; "user" config from /Users/fabio/.npmrc

//registry.npmjs.org/:_authToken = (protected) 
init.author.email = "spampinabio@gmail.com" 
init.author.name = "Fabio Spampinato" 
package-lock = false 
script-shell = "zsh" 

; node bin location = /Users/fabio/.nvm/versions/node/v16.13.0/bin/node
; cwd = /Users/fabio/Desktop/asd
; HOME = /Users/fabio
; 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 with the package.json dependency example and run npm i to reproduce the installed tree. Compare the resolved once dependency under pikchr-wasm with the expected once@npm:@fabiospampinato/once@1.0.0 alias. Done means npm preserves the alias rather than using the top-level once package.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.