Can't install node modules globally. Module not found error

Viewed 4311

I am trying to install modules globally using npm but the command is always failing. I used npm already in the past and it worked without problems. Now, after sometime without using npm and after updating both node and npm, I am not being able to use npm install <module> -g commands.

I searched and often times the fix is to add a NODE_PATH to the system variables or adding npm/bin to the PATH. I tried it as well and it didn't fix my problem.

Fabio@DESKTOP-SQP25OA MINGW64 ~
$ echo $NODE_PATH
C:\Users\Fabio\AppData\Roaming\npm\node_modules

Fabio@DESKTOP-SQP25OA MINGW64 ~
$ npm install forever -g
Error: Cannot find module 'pinkie-promise'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\Fabio\AppData\Roaming\npm\node_modules\npm\node_modules\request\node_modules\har-validator\lib\index.js:3:15)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
npm ERR! Windows_NT 10.0.15063
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Fabio\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install" "forever" "-g"
npm ERR! node v6.11.3
npm ERR! npm  v4.1.2
npm ERR! code MODULE_NOT_FOUND

npm ERR! Cannot find module 'pinkie-promise'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

I also don't know why, but I have node_modules folders at these locations (maybe because of different versions installs):

  • C:\Users\Fabio\AppData\Roaming\npm\node_modules
  • C:\Users\Fabio\node_modules
  • C:\Program Files\nodejs\node_modules

Maybe I am adding the wrong path to my PATH and NODE_PATH variables?

For NODE_PATH I tried: C:\Users\Fabio\AppData\Roaming\npm\node_modules

And for PATH: C:\Users\Fabio\AppData\Roaming\npm\node_modules\npm\bin

3 Answers
  1. Delete all node_modules on your system;
  2. Remove all system and user variables related to node and npm;
  3. Uninstall node;
  4. Reinstall the latest version of node.

That is what worked at the end.

Looks like you need to install "pinkie-promise" first, looks like this module has dependency on that.

You need to install pinkie-promise first:

npm install pinkie-promise -g

After that, install forever:

npm install forever -g
Related