Skip to content

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

Closed

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

Activity

  1. added
    Bug
    Needs Triage
    on May 22, 2024
  2. RobertAKARobin commented on Jul 29, 2024

    @RobertAKARobin

    I am also experiencing this on npm 10.8.2.

  3. milaninfy commented on Aug 2, 2024

    @milaninfy
    Contributor

    I believe it's not suppose to work like that, whatever git repo url provided in package.json that will be considered the packages. Based on what I can understand from the write up is that you want npm to recognize that there is a workspace package in git repository and you want to map @org/dep-y of your package.json to internal folder/workspace of git repository package.

    I couldn't find any reference of this behaviour in documentation, could you please provide link to it if you are referring in npm doc ?

  4. ematipico commented on Aug 2, 2024

    @ematipico
    Author

    As written at the beginning, if it's not a bug, then it's a limited behaviour in the functionality or the documentation.

    The documentation explains how to link a package via GitHub, however if this package is inside a workspace, the documentation doesn't explain how I can do that. If I attempt to do it by following the documentation, an error is thrown.

  5. milaninfy commented on Aug 9, 2024

    @milaninfy
    Contributor

    @ematipico As you mentioned Documentation does explain how to use package if that package is GitHub repository, however if a package resides inside a folder/directory within a repository, this behaviour is not supported as far as i know. You can only directly use GitHub repository as mentioned in the documentation.

  6. ematipico commented on Aug 9, 2024

    @ematipico
    Author

    @milaninfy I understand and know that; however, you didn't tell me how to resolve this issue. Is the documentation outdated? Is it a bug in the package's resolution when using a git repository? Is it missing functionality that requires an RFC?

  7. added
    Priority 1
    and removed
    Needs Triage
    on Aug 9, 2024
  8. milaninfy commented on Aug 9, 2024

    @milaninfy
    Contributor

    Assigning P1 for now, We may need to check few things, However it might not be inline with this bug report but a different bug related to workspaces and git.

  9. reggi commented on Sep 16, 2024

    @reggi
    Contributor

    I added to the docs that this is just a limitation of using git packages directly here in this npm/documentation#1279 available here https://docs.npmjs.com/about-packages-and-modules

  10. added a commit that references this issue on Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPriority 1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions