-
Notifications
You must be signed in to change notification settings - Fork 3k
'npm link' is creating symlinks with a relative path to modules in global node_modules #13369
Comments
Looks like this change is what caused the new behaviour:
On my box, cb is undefined so abs is getting set to false and relativeTarget is being chosen as the target. |
This started biting us again so I dug in a bit more. Here is the history of how things happened from what I can tell. Long ago, prior to version 2.7.5 all links (except on windows) were chosen to be be either absolute or relative based on the length:
Of course, if the path has a bunch of ../../ in front of a path from root, the absolute path from the root will always be shorter than the relative path. Then, in 3cf3b0c it was apparently decided that packages made available via a call to npm link should never be relative paths. A flag here is added to skip the block of code where the relative path could sometimes be triggered.
At this time the flag was only added to calls setting up a linked package:
and not calls to use that linked package:
Note that even though the new flag wasn't being passed to link calls of the second format, the !abs conditional still allowed paths to enter this block and absolute paths were still chosen when it made sense. Finally in commit b820ed4, the code is changed so that only direct requests for absolute paths are granted them. Otherwise the relative path is chosen even though it may be traversing all the way back up to the root. It seems like the 2 options for fixing this issue are either:
https://github.com/npm/npm/blob/latest/lib/link.js#L125
maybe something like this here (https://github.com/npm/npm/blob/latest/lib/utils/link.js#L61)
|
I like option 1 better. This seems like it will work fine. What was the reasoning for the changes that caused this @zkat? |
We're closing this issue as it has gone seven days without activity and without being labeled. If we haven't even labeled in issue in seven days then we're unlikely to ever read it. If you are still experiencing the issue that led to you opening this or this is a feature request you're still interested in then we encourage you to open a new issue. If this was a support issue, you may be better served by joining package.communty and asking your question there. For more information about our new issue aging policies and why we've instituted them please see our blog post. |
I'm opening this issue because:
What's going wrong?
The command:
...will correctly create a symlink in global node_modules (i.e. /usr/local/lib/node_modules) that has an absolute path to "linkedModule", but will then create a symlink in local node_modules (i.e. ./node_modules) with a relative path to the "linkedModule" link in /usr/local/lib/node_modules. This means that moving or copying the local module will break it.
How can the CLI team reproduce the problem?
Originallly produced in OS X:
The symlink created in node_modules will be to something like:
Instead of:
This is breaking a scripts my dev team rely on, as we require modules be able to be copied to other parts of the disk without breaking.
Note that the previous version of npm we were using did not have this behavior, and would use absolute paths. Unfortunately I don't remember which version that was.
supporting information:
npm -v
prints: 3.10.2node -v
prints: v4.4.7npm config get registry
prints: https://registry.npmjs.org/The text was updated successfully, but these errors were encountered: