22

In the past when I installed packages using npm(>=1.0) they would be installed locally, but not anymore.

My setup:

  • First I use nvm to install node.js.

  • My operating System:

    alfred@alfred-laptop:~/node/so/6513101$ cat /etc/lsb-release 
    DISTRIB_ID=Ubuntu<br>
    DISTRIB_RELEASE=10.10
    DISTRIB_CODENAME=maverick
    DISTRIB_DESCRIPTION="Ubuntu 10.10"
    
  • My node version:

    alfred@alfred-laptop:~/node/so/6513101$ node -v
    v0.4.8
    
  • My npm version:

    alfred@alfred-laptop:~/node/so/6513101$ npm -v
    1.0.15
    

Installing random package

alfred@alfred-laptop:~/node/so/6513101$ npm install notifo
notifo@0.0.2 ../../../node_modules/notifo 

In the past it would install into the same directory but it does not install in the same directory anymore. is my npm/node.js broken or am I missing something or does npm not anymore install local packages(inside same folder => ~/node/so/6513101/node_modules) which I thought was a cool feature because I could bundle all my dependencies so that other users did not have to install npm to use my code(I still believe users should install npm because it is a great product). The bundle command is gone so I can't use that? Could someone please explain to me what is going on?

Alfred
  • 60,935
  • 33
  • 147
  • 186

1 Answers1

61

npm walks up the folder tree until it finds a node_modules or a package.json and uses that as the root. What does npm root print out?

If you mkdir node_modules or create a package.json file, then it'll use the cwd.

EDIT: I won't see updates you post here. For better results, just post everything in the github issue, and let's do the support over there.

isaacs
  • 16,656
  • 6
  • 41
  • 31
  • 1
    hi Isaacs, thanks for the fast response. You are really amazing and I really like npm. I uploaded the commands I performed to http://pastebin.com/rctLbi3i. Most of the times I zip the folder upload to github and boom(all dependencies). But npm root now points to `/home/alfred/node_modules` instead of cwd. Is that something new? But you are right that when I create `node_modules` in cwd than after installing package it can be found in `node_modules` dir. Thanks for the help, but I am still a little confused. Did you update npm in anyway that I have different behaviour. I hope I made any sense. – Alfred Jun 29 '11 at 02:46
  • @isaacs Is this also true when installing npm itself locally? See http://stackoverflow.com/questions/29560416/how-can-my-module-require-a-specific-version-of-npm – Shawn Apr 10 '15 at 13:54