Windows10下Vue.js+Node项目执行npm start出现/usr/bin/env: ‘node’: No such file or directory报错的解决方案求助
Hey there, let's break down your problem step by step and get your Vue+Express app running smoothly again!
如何解决这个报错?
The core issue here is that you're running commands in the WSL Ubuntu environment (thanks to the Remote - WSL plugin), but that environment doesn't have Node.js properly set up. Here's what to do:
- First, confirm you're working in the WSL terminal (check the bottom-left corner of VSCode—it should say
WSL: Ubuntu). Then install Node.js and npm directly in your WSL Ubuntu instance:sudo apt update sudo apt install nodejs npm - Next, install nodemon globally in WSL (not just Windows):
sudo npm install -g nodemon - If you created a soft link earlier that might be causing conflicts, remove it first:
Newer Ubuntu Node.js packages include thesudo unlink /usr/bin/nodenodecommand by default, so you shouldn't need to recreate the link. - Don't modify the shebang line in nodemon.js—changing it to a Windows path like
#!C:\Progra~1\nodejs\node.exewill break it in the WSL environment, which doesn't recognize Windows-style file paths. - Make sure your project files are stored in the WSL file system (e.g.,
/home/your-username/your-project) instead of a Windows drive likeC:\. Working with Windows paths in WSL can cause environment confusion.
这行#!/usr/bin/env node代码存在的原因是什么?
That line is called a shebang, and it's critical for Unix-like systems (including WSL Ubuntu). Here's what it does:
- It tells the operating system which program to use to execute the script. In this case, it says "use the
nodeinterpreter that's available in your system's PATH environment variable". - Using
#!/usr/bin/env nodeinstead of a hardcoded path (like#!/usr/bin/node) makes the script portable—it works across different Unix-like systems where Node.js might be installed in different locations.
报错是否与Windows应用商店的Ubuntu应用和Remote - WSL插件有关?
Absolutely! Here's why:
- When you use the Remote - WSL plugin, VSCode runs all your terminal commands inside the WSL Ubuntu environment, not Windows itself. WSL has its own separate file system, environment variables, and installed software—so it can't access the Node.js you installed on Windows.
- The Windows environment variables you added (like
C:\Program Files\nodejs) don't apply to the WSL environment, which is why that change didn't help. - The Ubuntu app from the Windows Store is exactly the WSL environment you're interacting with via the Remote - WSL plugin—so this is the environment where you need to set up Node.js and nodemon.
If you follow these steps, your npm start command should find the node executable in WSL and run nodemon without issues.
内容的提问来源于stack exchange,提问作者Rotem Orbach
相关产品推荐
相关产品推荐

