You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

React Native新手求助:cmd执行yarn start报错Error: spawn cmd ENOENT

Fixing "spawn cmd ENOENT" Error When Running yarn start in React Native

Hey there! I’ve run into this exact error before, and it’s almost always tied to system environment setup or cached project files. Let’s work through the fixes step by step:

1. Check if C:\Windows\System32 is in your Path Environment Variable

The spawn cmd ENOENT error means your system can’t locate the cmd.exe executable, which lives in C:\Windows\System32. Here’s how to fix this:

  • Right-click "This PC" → "Properties" → "Advanced system settings" → "Environment Variables"
  • Under "System variables", find the Path variable and double-click it
  • Look for C:\Windows\System32 in the list. If it’s missing, click "New" and paste that path
  • Save all changes, then close every open cmd/PowerShell window and open a fresh one before running yarn start again. Old windows won’t pick up the updated environment variables otherwise.

2. Clear Cache and Reinstall Dependencies

Corrupted node modules or cached files can cause weird spawn errors too. Run these commands in your project directory:

# Clean Yarn's local cache
yarn cache clean

# Remove existing node modules folder
rm -rf node_modules

# Reinstall all project dependencies
yarn install

If that doesn’t work, try resetting the Metro bundler cache specifically:

yarn start --reset-cache

3. Verify Your Node.js Version

React Native plays best with LTS (Long-Term Support) versions of Node.js. Outdated or unstable versions can trigger compatibility issues. Check your current version with:

node -v

If you need to switch versions, use a tool like nvm (Node Version Manager) to install and switch to a recommended LTS version (like 18.x or 20.x).

4. Last Resort: Restart Your Computer

Sometimes environment variable changes or stuck system processes don’t take effect until a full reboot. If none of the above works, give your PC a quick restart and try running yarn start again.


内容的提问来源于stack exchange,提问作者Raja Tayyab

火山引擎 最新活动