Skip to content

Conversation

owlstronaut
Copy link
Contributor

@owlstronaut owlstronaut commented Aug 26, 2025

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 in node_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 from mainpkg would fail because npm tried to find a relative to b instead of relative to the original b 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

@owlstronaut owlstronaut force-pushed the resolve-transitive-external-deps branch from e44d29f to dcd4f8f Compare August 26, 2025 20:34
@owlstronaut owlstronaut marked this pull request as ready for review August 26, 2025 20:39
@owlstronaut owlstronaut requested a review from a team as a code owner August 26, 2025 20:39
@owlstronaut owlstronaut force-pushed the resolve-transitive-external-deps branch from dcd4f8f to 8e21bdf Compare August 27, 2025 16:59
@owlstronaut owlstronaut merged commit 3b54e9c into latest Aug 27, 2025
16 checks passed
@owlstronaut owlstronaut deleted the resolve-transitive-external-deps branch August 27, 2025 17:09
@github-actions github-actions bot mentioned this pull request Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] --install-links fails when local package has nested local dependencies
2 participants