I saw this issue: https://github.com/creationix/nvm/issues/668
the nvm maintainers convinced me that it was a bad idea to share global versions of modules across node versions. Now, I am not sure why we couldn't put different versions of the same module in the same directory, but that's not a battle I am going to wage right now.
(in other words):
~/.npm
/[email protected]
/[email protected]
/[email protected]
In other words it would not be that hard to put everything in one global dir, would it? IDK...enough of this battle.
The battle I do want to fight is that I am having a lot of trouble combining NVM with NPM's symlink features.
Sorry if this is a duplicate issue but I am looking for expert advice on how to work with NPM module symlink-ing and NVM => I am having a lot of weird issues, mostly what happens is that I see some bug in my program output but it's only because the code running is actually an old version of the project (the symlink points to an older version of the project somehow).
What are best practices for NVM + NPM symlink? thanks
Do you mean npm link?
npm link works via passing through global modules - which means it's specific to each version of node. As long as you're using the same version of node you linked from (which .nvmrc files in a project can help ensure, nvm use will auto-pick it up), it should work fine.
Can you elaborate on the issues you're running into?
Right, that's correct, but when I switch node versions (with NVM, of course), I believe I get linked to older versions of my project. What confuses me, is that the actual absolute path to my project has not changed. I guess I don't understand how symlinking works, but in reality, all that should be needed is the absolute path to my project root, which never changes. I guess I don't know why I get linked to older versions of projects (it's really bad when this happens for developer sanity LOL).
When you switch node versions, your link to foo will point to whatever the globally installed foo is in the new node version.
In other words, that's not how npm link works - it's tightly coupled to the global module installation directory of the current node version.
Huh, ok, perhaps what happened is that in some versions of node, I installed globally ($ npm install X -g), and in other versions of node I symlinked globally ($ npm link), that might be the culprit, is that reasonable?
so my next question for you is - is it possible (with NVM or NPM) to uninstall a module globally from all versions of node? or likewise, the inverse - install a module globally on all versions of node?
there needs to be one single global folder of node_modules that has all the versions :)
Yes, that's quite likely what happened.
No, it's not currently possible to run any command (npm install, npm uninstall, etc) simultaneously across all installed versions of node.
The issue you linked to describes the many reasons there should not be, and must not be, a single global node modules directory across node versions, so there's no need to revisit that here.
What I would suggest is: when you run npm link in a project, manually run that in every version of node you have installed. Then, when you install new node versions, use nvm install x --reinstall-packages-from=y to reinstall all the global packages in "y" in the new "x". That way, any node version you switch to will be linked to the desired project.
Ok, thanks, so what you're saying is that the symlinks will be copied too, to the new node version?
Yes, with nvm reinstall-packages y or nvm install x --reinstall-packages-from=y
This seems resolved - I'm going to close it for now, but will be happy to reopen it if needed.
Yeah I am good for now but if I have a related issue will revisit here, thanks for help
Most helpful comment
Yes, that's quite likely what happened.
No, it's not currently possible to run any command (
npm install,npm uninstall, etc) simultaneously across all installed versions of node.The issue you linked to describes the many reasons there should not be, and must not be, a single global node modules directory across node versions, so there's no need to revisit that here.
What I would suggest is: when you run
npm linkin a project, manually run that in every version of node you have installed. Then, when you install new node versions, usenvm install x --reinstall-packages-from=yto reinstall all the global packages in "y" in the new "x". That way, any node version you switch to will be linked to the desired project.