Installing Windows NodeJS causes problems when running npx and npm in WSL
MDN URL
https://developer.mozilla.org/en-US/docs/Learn_web_development/Getting_started/Environment_setup/Command_line
What specific section or headline is this issue about?
No response
What information was incorrect, unhelpful, or incomplete?
After installing WSL and VSCode + WSL integration I installed NodeJS with the Windows .msi installer. I then installed Prettier and ran into issues when trying to run npx prettier, it was giving an "invalid URL" error. And running npx only would open cmd.exe instead of staying in bash. I had issues with npm as well.
My first step to fix was uninstalling NodeJS from Windows and reinstalling it in WSL with apt. Second step was adding this (AI-suggested fix) to ~/.bashrc because my PATH was still messed up:
export PATH=$(echo $PATH | sed -e 's|/mnt/c/Program Files/nodejs:||' -e 's|/mnt/c/Users/bledk/AppData/Roaming/npm:||')
What did you expect to see?
Document should suggest to install NodeJS through WSL, not Windows installer.
Do you have any supporting links, references, or citations?
No response
Do you have anything more you want to share?
No response
MDN metadata
Page report details
- Folder:
en-us/learn_web_development/getting_started/environment_setup/command_line - MDN URL: https://developer.mozilla.org/en-US/docs/Learn_web_development/Getting_started/Environment_setup/Command_line
- GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/learn_web_development/getting_started/environment_setup/command_line/index.md
- Last commit: https://github.com/mdn/content/commit/5b20f5f4265f988f80f513db0e4b35c7e0cd70dc
- Document last modified: 2024-12-19T15:37:45.000Z
Thanks @bledking. It is perfectly valid to have nodejs installed in Windows and WSL - personally I work in windows most of the time, and move to WSL2 when it is needed for the toolchain I am interested in. I use nvm to manage node in both environments, but I have previously used the msi installer without any issues alongside VSCode, command line, prettier etc. This is the first I have seen of this issue. The two environments are separate and shouldn't bleed into each other as you are seeing. I don't see how they can.
We can't accept the suggested fix because many users will have no interest in WSL shouldn't be pushed down that path. I'm not sure the problem would reproduce for anyone else either, since I haven't seen it myself or seen reports of issues (though there may be some).
I'm therefore going to close this since at this point it looks like a "your setup" issue - and if it is broader than that, then it should be addressed through the various toolchain vendors.
Note though we might accept a PR that replaces the msi installation with NVM or FNM based installation of Node, since once users get a little of the way down the web development path they will likely need multiple node versions. That might not fix the problem though, since we don't know the root cause.