-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set the NODE_PATH variable when activating node #97
Conversation
When installing packages with npm using the global switch `-g` the package ends up in the proper directory (i.e. .nvm/$VERSION/lib/node_modules), however node is unable to require it since it somehow isn't searching on it's prefix. This patch fixes this behavior by manually adding the `node_modules` dir to the `NODE_PATH` variable.
I'm pretty sure this isn't the right way to circumvent npm, so you can require modules that are installed globally. This is straight from the npm faq: Q: I installed something globally, but I can't
|
@carter-thaxton I tend to disagree with you on that and apparently with npm itself as it seems. I agree on the fact that when you need to require something in your project then it's a dependency of the project, yes that's true, from the other hand though if that what you need to require in project A you also need to require it in project B, C, D etc then it's a global dependency, most often web frameworks, mongo, redis, testing frameworks, validation frameworks and many others, so those that need to be required by multiple projects in my opinion I believe should be installed globally. Many of those global installed modules that need to be required by multiple projects also provide system wide binary apps, for instance less module is also required by projects but at the same time it provides Indeed "polluting" Hope you take it in consideration again, the I just run in similar issue as I posted in #119 Thanks EDIT: |
I found this behavior confusing at first, too, but I've since come to love it. Check out this FAQ for more. Perhaps 'npm link' is what you're looking for. On Jul 5, 2012, at 5:11 AM, Panagiotis [email protected] wrote:
|
...and I was being hopeful that nodejs and npm would put an end to those...(and also put that constricting snake out of business, for that matter) :-( |
Regarding system-wide executables like lessc, nvm already supports those because they live in the same $PATH as the node binary itself. NODE_PATH is only needed if you want to require global libraries from local programs, which according to most the node core people (myself included) is a bad idea. I don't want nvm promoting such a practice. Also, this is just a script in your environment. It's like part of your bashrc. When people post their bashrc files on github, if there is a part you disagree with, you don't try to convince them to change, you fork and keep your own custom copy. Do the same with nvm. |
When using yeoman and it's various generators that feel like global packages rather than ones to install locally it's a real pain that these get installed into a version specific modules folder. Shouldn't globally installed packages be available globally rather than havign to reinstall everything when switching node version or worse as I am finding that I have switched node versions and now can't seem to update yeoman with npm as it appears to be unaffected either by npm update -g yo or even npm uninstall -g yo |
If you want a custom and persistent NODE_PATH, just set it in your .profile or .bashrc in the line before you source nvm. |
Thanks, yes I'd tried that. In the end what I discovered is that I had an existing couple of packages that I must have installed globally ages ago before I installed nvm. This meant that these packages were in my default PATH and once nvm was active were never effected by npm update or uninstall. The fix I found was to remove them from the folder in my default PATH then restart my terminal. Now I find the way nvm causes global packages to be installed per node version to be perfectly understandable and works fine. |
Possibly worth mentioning in the docs, warning people before they install nvm that it's a good idea to |
Just a 👍 to @atomless's suggestion. This bit me, too; spent a while trying to figure out why things were going haywire, before realizing that previously-installed A note post-install or similar would be grand, for future users. (= |
I'm happy to review a PR for that. If you have system global packages, the solution would be to |
(Which would you prefer, assuming I have the time to set aside to patching the docs: Just a mention in the README, or a notice on the install-script / first-run / something like that?) |
Definitely a mention in the readme - I'd also go for a notice - either once on "install", or, on-every-source as long as it can only do it when it detects global modules in the system |
On-every-source seems like a bad plan. I don't see why we should proscribe having globally-installed modules; just making sure people are aware that they're splitting their module-set by I'll try and take a look in a couple days. <3 |
Sounds good, thanks! |
Hey guys, looks like this no longer works in the current |
@Flackus this was intentionally removed many versions ago. NODE_PATH should never be set, and global modules should never be requireable. |
When installing packages with npm using the global switch
-g
the package endsup in the proper directory (i.e. .nvm/$VERSION/lib/node_modules), however node
is unable to require it since it somehow isn't searching on it's prefix.
This patch fixes this behavior by manually adding the
node_modules
dir to theNODE_PATH
variable.