Is there an existing issue for this?
This issue exists in the latest npm version
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
- 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" } }
- Install with the linked strategy:
npm install --install-strategy=linked
- Inspect the workspace's own
node_modules/:
ls -la packages/test/node_modules/
- Observe the unexpected self-link:
Environment
install-strategy = "linked"
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
When installing a monorepo with
--install-strategy=linked, every workspace that is not listed in the rootpackage.json'sdependencies/devDependencies/optionalDependenciesgets a symlink to itself created inside its ownnode_modules/directory, even though the workspace does not declare itself as a dependency.For example, given a workspace
packages/testwhose package is named@namespace/testand which is not declared in the root manifest, the following symlink is created: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
IsolatedLinknode 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
exportsfield 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:…with no extra
packages/<ws>/node_modules/<ws>self-symlink.Steps To Reproduce
node_modules/:Environment