npm / npm/cli

[BUG] npm install remote package does nothing when the package contains a reference to a similar local package

Open
#7,084 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Priority 2 Release 10.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

When creating and testing a library locally, it is useful to use local packages instead of remote package in order to prevent publishing too much releases for testing purposes.

{
  "dependencies": {
    "my-library": "file:../"
  }
}

Here, for instance, would refer to the following architecture.

my-library/
  package.json
  test-project/
    package.json --> The package.json showed above

When extracting the test-project folder out of this architecture in another location of the file system and running npm install my-library (published version of the library), it says that the library has been installed but not only it does nothing to the package.json, it also does not warn for a parent folder that does not exist.

home/
  user/
    test-project/
      package.json --> The package.json showed above

This makes it very difficult for library author to create templates that can easily be cloned using degit and install the latest version of this library.

Expected Behavior

Not only does npm install should check for whether a package using a relative path does exist on the current file system, it should also install the remote package if no local package has been found.

This would greatly improve the user & developer experience by not having to manually override the package.json and remove the references to the local library.

Notes: workspaces have nothing to do with this issue and does not solve the issue when the subfolder gets extracted out of its context.

Notes: running npm install --force does not solve the issue either.

Steps To Reproduce
  1. Create a new folder and initialize a Node.js project using npm init --yes and use the name of a library that already exist in the NPM Registry (ex: react)
  2. Create a subfolder of this folder and create a new Node.js project using npm init --yes
  3. Issue a local installation of folder's Node.js project (local react) into the subfolder's Node.js project
  4. Copy the subfolder to another location on the file system
  5. Install a remote version of react into the copied subfolder
  6. See that the package.json dependencies gets unchanged
Environment
  • npm: 10.2.4
  • Node.js: 21.4.0
  • OS Name: Archlinux
  • System Model Name: Huawei Mate 18
  • npm config:
; "user" config from /home/amin/.npmrc

prefix = "/usr/local"

; node bin location = /usr/bin/node
; node version = v21.2.0
; npm local prefix = /home/user/Documents/code/javascript/npm-bug-repro
; npm version = 10.2.4
; cwd = /home/user/Documents/code/javascript/npm-bug-repro
; HOME = /home/user
; 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

Reproduce the issue with npm 10.2.4 and Node.js 21.4.0 using the listed npm init, local file:../ dependency, copied test project, and remote install steps. Trace how npm install handles the relative dependency when its parent path is absent; done means the remote package is installed and package.json is updated, or the missing local package is clearly reported.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli
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.