3

Hey all– I'm on macOS Catalina. I've changed my NPM root and $PATH while trying to get things to work, and I think I broke something, though I'm not exactly sure what. My issue is very specifically with NPM, which is having a persistent problem running installed modules both locally and globally. When I try to install a dev tool like Nodemon or a framework like Electron, I get error codes like:

sh: electron: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! electron-quick-start@1.0.0 start: `electron .`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the electron-quick-start@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I've consulted a lot of resources and a lot of questions on this site, but I'm not experienced enough to accurately troubleshoot this issue and identify what's going on. While I'm shooting in the dark, I may be fixing one thing and breaking another, so I'm coming here to see if I can get a comprehensive answer.

I'll add that I've found a few workarounds, if this makes the issue clearer at all. I can get some modules (in this example Nodemon) to run by adding this "dev" script to the package.json:

"scripts": {
    "dev": "node ./node_modules/.bin/nodemon server.js"
  }

So I can access local project modules by specifying the path of the Module, but I can't just say "nodemon server.js", either in the dev script or from the command line, where it should have been installed globally. If I look in the specified npm -g root folder, the packages I'm trying to run are definitely in there, so it's not that it's not installing. This seems to be true of packages in every Node project I create.

My npm -g root is /usr/local/lib/node_modules and npm config get prefix is /usr/local.

zeo
  • 31
  • 2
  • 5
  • Check if your `npm -g root` and `npm config` (specifically prefix) are set correctly. May wish to include that in an edit > https://stackoverflow.com/a/45339910/2312051 – Denis Tsoi May 22 '20 at 22:16
  • `npm -g root ` is /usr/local/lib/node_modules and `npm config get prefix` is /usr/local. Is that correct? @DenisTsoi – zeo May 22 '20 at 22:19
  • with the dev script - I thnk you can use `"./node_modules/.bin/nodemon server.js"` - i.e. omit node (but that's a different issue to npm right now) – Denis Tsoi May 22 '20 at 22:28
  • That works for this project, but it doesn't solve this problem for other applications. For example, I'm trying to run a React default project and getting the same issue, and it's getting crazy unwieldy to change every script for every project I download. – zeo May 22 '20 at 22:35
  • since `npm -g root` is pointing to `usr/local/lib/node_modules` and `npm config get prefix` is set to `usr/local` - there's two things I'd like to ask: - 1. Check if `/usr/local/bin` has nodemon installed (you can `cd` to `usr/local/bin` and look at the directory) 2. Check if your $PATH is pointing to `/usr/local/bin` (`echo $Path`) – Denis Tsoi May 22 '20 at 22:35
  • I understand this is kind of tricky - we're just trying to see if the paths for npm/node are set correctly on your machine - – Denis Tsoi May 22 '20 at 22:35
  • alternatievly you can use `which node` - and this should print out the directory of where node is installed - hopefully in `/usr/local/bin/node` – Denis Tsoi May 22 '20 at 22:36
  • Which node is /usr/local/bin/node, but $PATH is this crazy long string: `/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/opt/ImageMagick/bin:/Applications/Wireshark.app/Contents/MacOS` – zeo May 22 '20 at 22:48
  • when you install `npm i -g nodemon` - can you print out `which nodemon`? - as well as `which electron` - thanks – Denis Tsoi May 22 '20 at 23:09
  • `/usr/local/bin/nodemon` and `/usr/local/bin/electron`, respectively. – zeo May 22 '20 at 23:12
  • Global packages are working now for some reason but I'm still having trouble with package.json scripts unless I install the package globally – zeo May 22 '20 at 23:15
  • when you install the package with `npm i` - and run `npm dev` what errors do you get? – Denis Tsoi May 22 '20 at 23:19

0 Answers0