0

Tried everything. Tried all the steps below, didn't work so I nuked my droplet and rebuilt to start over and try again. I'm Using Ubuntu. First thing once I ssh into my droplet was install node and npm via:

https://nodejs.org/en/download/package-manager/

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

Then

npm -v
5.6.0
node -v
v8.11.3

Then I try to install a package globally. I tried electron and it failed so I began messing with the node modules folder as I was getting the permission error with the fix documented here:

https://askubuntu.com/questions/869168/node-modules-have-755-permissions-what-permissions-should-i-set-so-that-npm-don

No luck. So I tried the solution documented here: NPM global install "cannot find module"

echo $NODE_PATH
/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript:/home/username/.npm-global/lib/node_modules

So that didn't work either. This is the error now when I try and install any package globally:

npm install -g electron

I get:

Error: Cannot find module '/root/.npm-global/lib/node_modules/nightmare/node_modules/electron/install.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! electron@1.8.7 postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the electron@1.8.7 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-08-03T03_26_03_827Z-debug.log

This error for any package I try to install. Not sure what else to try. Don't want to wipe out the droplet and start over...

Taylor A. Leach
  • 2,115
  • 4
  • 25
  • 43
  • From the error message, looks like you're running node as root and it's looking for the package in `/home/root/.npm-global/lib/node_modules` directory, but this directory has not been added to your **NODE_PATH** environment variable (looks like you forgot to change **username** to your actual username when adding `/home/username/.npm-global/lib/node_modules` to your **NODE_ENV**) – fardjad Aug 03 '18 at 04:10
  • And as a side note, you might want to avoid installing packages globally. Instead you can install modules locally and run their bin scripts via npm scripts (defined in `package.json` file.) – fardjad Aug 03 '18 at 04:14
  • The only reason I am trying to install them globally is that the app that I am trying to push to the droplet uses electron and nightmare.js and it said nightmare was undefined when I ran it... thus opening up this new can of worms. Not even sure if that was the issue but I was trying to eliminate variables. It is installed globally on my mac so thought I'd try... – Taylor A. Leach Aug 03 '18 at 04:17
  • Yeah that's what was super weird because they are all defined as dependancies in the package.json files. I require nightmare and store it as a const, but it was undefined somehow. Works perfect locally. – Taylor A. Leach Aug 03 '18 at 04:34

0 Answers0