10

I have node.js 0.8.14 installed on Ubuntu 12.10. I created a directory in my home directory with a sub directory node_modules. I want to install some local node modules there but running
npm install myModule in this directory installs this module in /usr/local/lib/node_modules/ (same behavior as installing the module with the -g flag

There is no node path in .bashrc.

Any idea how I can install local node modules?

vsdev
  • 321
  • 1
  • 2
  • 8

3 Answers3

20

After some further research I found the solution.

Running the command npm config ls revealed that the default config global=false (you see the default config with npm config ls -l) was overwritten by global=true in /home/vsdev/.npmrc and /usr/local/etc/npmrc.

Reverting this to global=false solved the issue.

vsdev
  • 321
  • 1
  • 2
  • 8
  • Awesome! I am just new to node and was struggling because local grunt wasn't being found. It took me quite a while to find that the problem was this config. Thanks! – Luís Bianchin Jul 25 '14 at 03:40
4

That is odd.

  • FYI you don't need to create the node_modules directory, npm will do that for you
  • npm normally just installs to the current directory. Even if the package you are installing is configured to prefer global installation, npm will install it locally unless you explicitly pass the -g parameter.
  • can you run the following shell commands and confirm npm is really the real npm?
    • which npm
    • alias | grep npm
Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
1

npm install load all in node_modules then it might be version 3 behaviour http://blog.npmjs.org/post/110924823920/npm-weekly-5 or as mentioned by @vsdev so once you make sure it version 3 behaviour and u want to go with it then its fine else follow below

1- uninstall all modules.. into the node_modules folder in your project then execute: npm uninstall *

2- Tell npm to install with legacy bundling for this one install:

npm install --legacy-bundling A "permanent" alternative:

Set your npm config to always use legacy bundling...

npm set legacy-bundling=true

.. and run as usual:

npm install

*fetching dependencies with legacy bundling will take a lot more time because many several different versions of the same dependencies will be installed.

Furqan Freed
  • 366
  • 1
  • 3
  • 9