Node not find global module

So, I understand that this is a pretty general title and question, but I looked at so many answers, but unfortunately none of them seem to work for me. I hope to get a little more information from myself, maybe someone has a specific answer or knows exactly which answer to redirect me to.

My problem: when I install node modules globally (e.g. npm install -g nightmare), I cannot access them in the project folder. I get an error message:

module.js:471
    throw err;
    ^

Error: Cannot find module 'nightmare'
...

From what I have read so far, installing the module locally inside the project folder seems to be the preferred practice (is that true?), But so far at the development stage I would like to be able to use the modules I installed globally. I am new to node.js, so I am still discovering what “normal practice” is for these things. I first installed node using Homebrew, but since I had problems with how everything was installed and the path (which people said was normal when using Homebrew), I decided to try a clean slate by removing Homebrew and then node and NPM I reinstalled only node and NPM through the site, but I still cannot access my global modules.

, node_module , , . , . $NODE_PATH , , .

--verbose - /Users/<user>/.npm-packages/lib, , , , , , /usr/local/lib/node_modules, , . , (- ) ... ? , , , , $NODE_PATH .

- - , . , .

!

+4
1

, .

: :

npm install nightmare --save

:

npm install -g nightmare
npm link nightmare
+11

Source: https://habr.com/ru/post/1670777/


All Articles