Skip to content

[BUG] install-strategy=linked creates an unnecessary self-link inside every undeclared workspace's node_modules/ #9398

@manzoorwanijk

Description

@manzoorwanijk

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 installing a monorepo with --install-strategy=linked, every workspace that is not listed in the root package.json's dependencies / devDependencies / optionalDependencies gets a symlink to itself created inside its own node_modules/ directory, even though the workspace does not declare itself as a dependency.

For example, given a workspace packages/test whose package is named @namespace/test and which is not declared in the root manifest, the following symlink is created:

packages/test/node_modules/@namespace/test -> ..

This symlink is not pointed to by any edge in the dependency graph. It is created as a side effect of how the isolated reifier parks the workspace IsolatedLink node off-root when the workspace is undeclared.

Packages that need to resolve themselves by name rely on Node.js's built-in self-referencing via the exports field instead.

Expected Behavior

No self-link should be created inside an undeclared workspace's node_modules/. The on-disk layout should match the "After" example shown in #9076's description:

packages/a/node_modules/@scope/b -> packages/b   # @scope/a depends on @scope/b

…with no extra packages/<ws>/node_modules/<ws> self-symlink.

Steps To Reproduce

  1. Create a monorepo where the root does not list its workspaces as dependencies:
root/
  package.json        # { workspaces: ["packages/*"] } — no dependencies on workspaces
  packages/
    test/package.json # { "name": "@namespace/test", "version": "1.0.0" }
    a/package.json    # { "name": "@namespace/a", "version": "1.0.0", "dependencies": { "abbrev": "^1.0.0" } }
  1. Install with the linked strategy:
npm install --install-strategy=linked
  1. Inspect the workspace's own node_modules/:
ls -la packages/test/node_modules/
  1. Observe the unexpected self-link:
@namespace/test -> ..

Environment

install-strategy = "linked"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions