Skip to content

[BUG] npm doesn't correctly resolve workspaces when defining a dependency using GitHub URLsΒ #7554

@ematipico

Description

@ematipico

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

npm allows to define a dependency using git or GitHub URLS:

However, I think there's a limited or buggy functionality when trying to install a dependency from a git repository that contains a workspace.

For example, here's the main package:

{
	"dependencies": {
		"@org/dep-y": "git://github.com/org/monorepo.git"
	}
}

The monorepo project contains a root package.json that defines a workspace:

{
	"name": "@org/monorepo",
	"workspaces":  ["packages/**"],
	"publish": false
}

And packages/ contains the library dep-y:

{
	"name": "@org/dep-y",
	"publish": true
}

Current behaviour: npm links @org/dep-y to @org/monorepo

Expected Behavior

Expected behaviour: npm links @org/dep-y to @org/dep-y inside packages/dep-y/package.json

Steps To Reproduce

  1. Have a setting like this:
    For example, here's the main package:

    {
    	"name": "external-lib",
    	"dependencies": {
    		"@org/dep-y": "git://github.com/org/monorepo.git"
    	}
    }

    The monorepo project contains a root package.json that defines a workspace:

    {
    	"name": "@org/monorepo",
    	"workspaces":  ["packages/**"],
    	"publish": false
    }

    And packages/ contains the library dep-y:

    {
    	"name": "@org/dep-y",
    	"publish": true
    }
  2. Run npm i inside the external-lib lib

  3. Look that the symbolic link inside node_modules/@org/dep-y points to the whole workspace

  4. Try to import the library import("@org/dep-y") see errors because it uses package.json of the workspace

Environment

  • npm: 10.2.4
  • Node.js: v20.11.1
  • OS Name: macOS
  • System Model Name: Macbook Pro
  • npm config: I have none

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingPriority 1high priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions