1

I tried dealing with the Node.js permission issue for installing new modules and in the process it got totally screwed up so when I install something globally, it just doesn't have a terminal function. For instance, the default path used to be /usr/local/lib/node_modules, but right now whenever I install something with npm -g, it installs it in my OSX home folder (!!) and it is not accessible globally. I tried removing everything, reinstalling Node.js, nothing helps. It all happened after following this thread

Using these lines:

sudo chown -R $(whoami) ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules

Please help.. I've been at it for hours now :(

Community
  • 1
  • 1
Erez Hod
  • 1,813
  • 2
  • 23
  • 47

2 Answers2

0

Have you verify the configuration of npm?

Run the following command

npm config ls -l

To check the configuration of npm (both with and without sudo).

You may try to uninstall Node.js, remove the npm configuration files (npmrc) if any, or any other npm folder left, and install again.

Changing the permission of a system folder as /usr/local/lib/node_modules is a bad idea.

Víctor Iniesta
  • 158
  • 1
  • 1
  • 7
0

It sounds like there are several problems.

right now whenever I install something with npm -g, it installs it in my OSX home folder (!!) and it is not accessible globally.

npm maintains a cache in ~/.npm in your home directory. This is not an installation location, just a cache of downloaded packages and other data. If this is causing you grief, you can get rid of it temporarily with

npm cache clean

npm will recreate and repopulate the cache as it runs.

One way to rescue the situation is to download and run this script < https://github.com/DomT4/scripts/blob/master/OSX_Node_Removal/terminatenode.sh > which will remove node completely. You can then install with the installer < http://nodejs.org/download/ > or homebrew, whichever you prefer.

One last point, though, is that when you install a package globally, you cannot require it: you get new commands. For example:

$ jshint -bash: jshint: command not found $ npm install -g jshint $ jshint $

Now I have the jshint command installed and can use it to analyze source files; but I cannot require('jshint') from any code, because that doesn't look in the global node_modules directory. This is intentional; the goal is to make each package declare its dependencies completely, so it is easier to move a package from one host to another without having to figure out what undocumented dependencies need to be installed on the target system.

Sam Mikes
  • 10,438
  • 3
  • 42
  • 47