-1

I just installed WSL2 and Ubuntu as one of my terminal options in Windows Terminal, as I want to now do my JavaScript development in Windows instead of Mac (our clients are all Windows users).

When I try to build my Node package with "npm run build", which is just a script of "babel lib -d dist", I receive the following error, which suggests to me either Windows, the WSL2, or something in my environment variables is pushing a "C:" in front of "\mnt\c", generating the following error:

internal/modules/cjs/loader.js:883
  throw err;
  ^

**Error: Cannot find module 'C:\mnt\c\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'**
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

And here is my PATH with 'printenv' in Ubuntu:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/Program Files/VanDyke Software/Clients/:/mnt/c/Program Files (x86)/Razer Chroma SDK/bin:/mnt/c/Program Files/Razer Chroma SDK/bin:/mnt/c/Program Files (x86)/Razer/ChromaBroadcast/bin:/mnt/c/Program Files/Razer/ChromaBroadcast/bin:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/Windows/system32/config/systemprofile/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/csomm/AppData/Roaming/nvm:/mnt/c/Program Files/nodejs:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/Git/mingw64/bin:/mnt/c/Program Files/Git/usr/bin:/mnt/c/Program Files (x86)/QuickTime/QTSystem/:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin:/mnt/c/Users/csomm/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/csomm/AppData/Local/atom/bin:/mnt/c/Users/csomm/AppData/Roaming/nvm:/mnt/c/Program Files/nodejs:/mnt/c/Program Files/JetBrains/WebStorm 2021.3.1/bin:/mnt/c/Users/csomm/AppData/Local/Programs/Hyper/resources/bin:/snap/bin

Any thoughts/ideas?

  • What does `which npm` show? – NotTheDr01ds Jan 20 '22 at 20:41
  • /mnt/c/Program Files/nodejs/npm – Chris Sommers Jan 20 '22 at 20:43
  • Actually - this looks like [Windows Subsystem for Linux (WSL) using shared Node.js installation with Windows: Node.js npm & npx binaries not working](https://stackoverflow.com/questions/54034404/windows-subsystem-for-linux-wsl-using-shared-node-js-installation-with-windows) -- I'm going to add another answer over there with a little additional information. Check back on that question in a bit. – NotTheDr01ds Jan 20 '22 at 20:51
  • No, that didn't work... NVM is installed/working as is NPM, but trying to run NPM (which re-installing NVM tries to do) still throws the error. I could use the "hack" that was the second answer there, but I'd rather find the right solution – Chris Sommers Jan 20 '22 at 21:10
  • But is the NVM version the Windows one or the Linux one? If it's the Linux version, `type nvm | head -1` will show `nvm is a function`. – NotTheDr01ds Jan 20 '22 at 21:21
  • Also note that, when activated with `nvm`, the `$PATH` should have `/home//.nvm/versions/node//bin`. Yours isn't showing anything like that, so it doesn't look like it's getting activated properly, leaving the Windows version as the only one on the path. – NotTheDr01ds Jan 20 '22 at 21:28
  • 1
    Its the linux version and the type nvm | head -l returns "nvm is a function" – Chris Sommers Jan 20 '22 at 21:33
  • also, i tried the 'hack' in the other post replies, and it errored with this: Cannot find module '\\wsl$\Ubuntu\mnt\c – Chris Sommers Jan 20 '22 at 21:34
  • Yeah, definitely agree that the hack isn't the way to go. So `nvm` is the Linux version, but the Windows version is still the only one showing up on the path. And we know `nvm` is getting loaded in your `~/.profile` because the function is defined .... Ok, still thinking about causes, and will hopefully come back in a bit with some additional questions, at least. – NotTheDr01ds Jan 20 '22 at 21:40
  • i ended up figuring it out - i installed NPM directly from within Ubuntu (it would still run and behave as if it were installed, owing to it having been installed via Command Prompt) and now it works! – Chris Sommers Jan 20 '22 at 21:57
  • Interesting - That's what I was proposing (and the [answer here](https://stackoverflow.com/a/62886232/11810933)), but then it looked like you had already done that -- I wouldn't have thought `type nvm | head -1` would have shown it to be a function if it was the Windows version. But good to hear you got it working. – NotTheDr01ds Jan 20 '22 at 22:00
  • Yes, the reason that didn't work is because it was installing NVM first, and then the NPM would fail. NPM had to be installed in Ubuntu independently as a standalone. – Chris Sommers Jan 20 '22 at 22:25

1 Answers1

0

This has been resolved. The problem was that I had installed NVM/NPM first in Command Prompt, and owing to Windows WSL2 cross-utilizing Linux and Windows applications, NVM that was installed in Windows would run in my Ubuntu just fine, but the NPM would fail owing to relative path issue.

Solution was to "re-install" NPM natively within Ubuntu. Now it works perfectly.