1

I've been at this for hours, and I've tried endless things and reinstalled NodeJS so, so many times.

I'm on Win10. I cannot run npm, it seems to have some PATH error I cannot get around this:

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'

This path looks screwy, I know. I've removed any roaming entries in the PATH var for nodejs or npm. Only

C:\Program Files\nodejs

remains at this point.

Is there any real solution that works for Win10 every time?

I'll do anything at this point. I've tried so, so many things that I found here or a dozen other sites.

I'm not trying to do anything special. I just want to run npm at the command line successfully--update itself, check itself, anything. No matter how it's invoked, I get the error above.

I mean, what should the PATH look like? How can I make this thing happy?

Thanks for any help.

Breck
  • 11
  • 2
  • Which version of Node are you installing? Are you just downloading the MSI file from https://nodejs.org/en/download/ or are you doing something different? I have Node 14.15.4 / NPM 6.14.10 on Windows 10 and they work just fine in Powershell, CMD and Git Bash – Phil Aug 23 '21 at 07:09
  • FYI, this isn't a path issue. It looks like it is correctly resolving `npm` to `C:\Program Files\nodejs\npm` (or `C:\Program Files\nodejs\npm.cmd`). It's the contents within that command / script that are resolving things incorrectly. I suspect you may have a `.npmrc` file in your user profile that has an incorrectly configured `prefix` – Phil Aug 23 '21 at 07:17
  • @Phil but look at that whole path. node_modules\npm\bin repeated twice. That can't be right, right? – Breck Aug 23 '21 at 07:22
  • @Phil I have v14.17.5 installed. Yes, from same site you pathed above. – Breck Aug 23 '21 at 07:23
  • The final path comes from the `npm` script file (either `npm` for bash or `npm.cmd` for Powershell / CMD) and it figures that out from any configured `prefix`. Can you run `node.exe`? if so, try running `node.exe "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" prefix -g` and see what it shows – Phil Aug 23 '21 at 07:30
  • If it shows `C:\Users\\AppData\Roaming\npm` (as it does on mine), perhaps try deleting that folder – Phil Aug 23 '21 at 07:38
  • @Phil I did a repair on my NodeJS install and now it's added the PATH entry: [C:\Users\breck\AppData\Roaming\npm] But just know, I still do have that entry I'd had originally: [C:\Program Files\nodejs] Still same symptoms with the repair (and the new PATH addition). I will try to *delete* that ...\Roaming\npm folder as you suggested. – Breck Aug 23 '21 at 20:18
  • And yes, running node.exe as you specified did indeed yield the [C:\Users\breck\AppData\Roaming\npm] folder. – Breck Aug 23 '21 at 20:22
  • I deleted the AppData\...npm and \npm-cache folders. Relaunched cmd and get the same results. – Breck Aug 23 '21 at 20:29
  • The only thing I got to (seemingly?) work was running [SET PATH=C:\Program Files\Nodejs;%PATH%] before running npm. A hack from here: https://stackoverflow.com/questions/24721903/npm-npm-cli-js-not-found-when-running-npm – Breck Aug 23 '21 at 20:47

0 Answers0