ITADN
npm/cli/Issues

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

#9398Openmanzoorwanijk 创建于 2026-05-23
M
manzoorwanijkcommented
## Is there an existing issue for this? - [x] I have searched the existing issues ## This issue exists in the latest npm version - [x] 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](https://nodejs.org/api/packages.html#self-referencing-a-package-using-its-name) 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" } } ``` 2. Install with the linked strategy: ``` npm install --install-strategy=linked ``` 3. Inspect the workspace's own `node_modules/`: ``` ls -la packages/test/node_modules/ ``` 4. Observe the unexpected self-link: ``` @namespace/test -> .. ``` ## Environment - npm: 12.0.0-pre.0.0 (also reproduces on earlier versions since #9076 landed) - Node.js: v24.15.0 - OS Name: macOS 26.5 - System Model Name: MacBook Pro - npm config: ```ini install-strategy = "linked" ```
0 条评论