16

I feel like I need to be able to install global npm packages separately into the NVM dir.

$ nvm install v0.11
######################################################################## 100.0%
Now using node v0.11.16
$ node-inspector
Node Inspector v0.9.2
Visit http://127.0.0.1:8080/debug?port=5858 to start debugging.

my node-inspector stopped working!

$ npm update -g
<bunch of updating, succeeds>

Maybe this will help... Nope! still broken. Sigh. Perhaps... node-inspector doesn't work for a v0.11.16 (that's being run on nvm). Perhaps. Who knows. Well, time to abort.

$ nvm use system
Now using system version of node: v0.10.32.
$ node-inspector --version
dyld: lazy symbol binding failed: Symbol not found: _node_module_register
  Referenced from: /usr/local/lib/node_modules/node-inspector/node_modules/ws/build/Release/bufferutil.node
  Expected in: dynamic lookup

dyld: Symbol not found: _node_module_register
  Referenced from: /usr/local/lib/node_modules/node-inspector/node_modules/ws/build/Release/bufferutil.node
  Expected in: dynamic lookup

[1]    93845 trace trap  node-inspector --version

Okay.... Well.... Shit.

So anyway, at this point I'm not looking for instructions on how to fix. I may well be hosed. The main question here is what am I supposed to do to manage these npm packages which are meant to be command line tools and which have compiled components that appear tied to specific versions? I understand that when I install nvm and incorporate it into my system, my shell is able to switch its $PATH so that when I call node and npm, they will run using the node version I picked.

But it appears as though the global npm packages get put into /usr/local/bin/ somewhere and they're just stuck there and become unable to follow what I do with nvm -- While it may not be the case for the "theoretically well-behaved node package", in practice (for something like node-inspector at least) it sure looks like it's liable to gleefully explode when not executed using the node that installed it.

In the meantime I have to basically npm remove -g <package> && npm install -g <package> any package that I find behaves strangely in this manner, every single time that I want to run that package under a new node version using nvm.

This seems wrong.

Is it wrong?

And, a corollary to this would be that every time I invoke nvm powers to test some given node.js app with a different version of node, I pretty much should do it by cloning it in a whole new directory and starting fresh, because otherwise I'll probably find out that I will need to rm -rf node_modules && npm install just to make it function at all...

3
  • I'll come clean... the node-inspector "wasn't working" possibly because I did not see the firewall prompt that came up. Still this does not invalidate my question. I still experience the dyld bug etc. and I need to take the rather drastic measure of removing and reinstalling (which does recompilation etc) of packages. I want to make this unnecessary by configuring npm -g to use a path relative to the nvm node version. Is this possible?
    – Steven Lu
    Mar 13, 2015 at 2:29
  • I know that my answer is correct, if you don't mind accepting. ;-)
    – seangates
    Apr 3, 2018 at 5:22
  • Thanks, I haven’t used nvm in a while
    – Steven Lu
    Apr 3, 2018 at 14:13

2 Answers 2

24

UPDATE October 2020:

If you've already installed the desired Node version, according to the documentation this is also available:

nvm reinstall-packages <from-version>

Props to @rashi for pointing out the syntax above.


From the nvm help message:

nvm install [-s] <version>                Download and install a <version>, [-s] from source. Uses .nvmrc if available
    --reinstall-packages-from=<version>     When installing, reinstall packages installed in <node|iojs|node version number>
    --lts                                   When installing, only select from LTS (long-term support) versions
    --lts=<LTS name>                        When installing, only select from versions for a specific LTS line

The relevant flag is --reinstall-packages-from=<version>. Simply re-run your command (example):

$ nvm install v6.9.2 --reinstall-packages-from=v4.4.5
2
  • 2
    now it's changed to nvm reinstall-packages <from-version>
    – Rashi
    Oct 3, 2020 at 11:36
  • 1
    Suggestion: use fnm now.
    – seangates
    Aug 23, 2022 at 0:06
0

I may have misunderstood your situation, but it seems like you need to install all global packages you use separately for each node version you are using. The reason it works like that is that you may need different versions of packages for different node versions. So whenever you use nvm use ... it changes paths to global packages to the packages installed for the selected version of node.

Hope it helps.

3
  • I havent been back to playing with nvm, but I was under the impression that nvm in no way helps you by helping to manage global npm dependency files along with the node versions. So since there isn't even anything that functions at a global level similar to package.json, well... the situation is not very ideal...
    – Steven Lu
    May 5, 2015 at 0:44
  • As I wrote, nvm stores all global packages in the separate folder for each node version for compatibility reasons. Also when you use npm link, the symlink to the package goes in the same folder, essentially making it global. You don't really need any manifest file to manage that - just npm install -g / npm uninstall -g. I usually just have a bash script that installs all the packages needed for the project and commit it together with the project so it's easy for others to maintain global dependencies.
    – esp
    May 9, 2015 at 9:43
  • I will try to verify next time that nvm is actually swapping symlinks or otherwise doing something to help manage these global resources when I change the node version. That would be exactly what I need, and for whatever reason it wasn't working for me when I wrote the question. Thanks.
    – Steven Lu
    May 14, 2015 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.