fix: installLinks works with transitive external file dependencies #8534
+77
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #8342
What
This PR fixes an issue where npm fails to properly handle transitive file dependencies when using the --install-links flag. Previously, when a file dependency had its own file dependencies, npm would fail to resolve them correctly, resulting in
ERR_MODULE_NOT_FOUND
errors.Why
When using
npm install --install-links
to install a local package that has its own file dependencies, npm would attempt to resolve the transitive dependencies relative to the installed location innode_modules
rather than the original source location. This caused the installation to fail because the transitive dependencies couldn't be found at the incorrect path.For example, given this structure:
Running
npm install --install-links ../b
frommainpkg
would fail because npm tried to find a relative tob
instead of relative to the originalb
source location.How
The fix introduces logic to detect transitive file dependencies when
--install-links
is used and ensures they are resolved relative to their parent's original source location:Detect transitive file dependencies: When a parent package was installed (not linked) due to
--install-links
and has file dependencies of its own, those are identified as transitive file dependencies.Preserve original paths: The parent's resolved` field (e.g., file:../b) is used to determine the original source location.
Correct path resolution: Transitive file dependencies are resolved relative to the parent's original location rather than its installed location in
node_modules