按官方文档创建React Native应用,运行npm start遇spawn cmd ENOENT错误
spawn cmd ENOENT Error When Running npm start with Expo 2.6.14 Hey there, let's get that annoying spawn cmd ENOENT error sorted out for your React Native Expo project.
What's Causing This?
That error pops up because your Windows system can't find cmd.exe—the command prompt executable. Looking at your error log's PATH entry:
8 verbose lifecycle @~start: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\xampp\htdocs\native\AwesomeProject\node_modules.bin;C:\Program Files\Git\cmd;C:\xampp\php;C:\Program Files\nodejs;;C:\Users\Administrator\AppData\Roaming\Composer\vendor\bin;C:\xampp\php;C:\Users\Administrator\AppData\Roaming\npm
Notice that C:\Windows\System32 (where cmd.exe lives) is missing from your system's PATH variable. That's the root issue.
Step-by-Step Fix
Add System32 to your PATH environment variable
- Right-click "This PC" → select "Properties"
- Click "Advanced system settings" → go to the "Advanced" tab → hit "Environment Variables"
- Under "System variables", find the
Pathentry and click "Edit" - Add a new line with
C:\Windows\System32 - Save all changes and close every open command prompt/terminal window
Verify and Test
- Open a brand new terminal window
- Run
echo %PATH%to confirmC:\Windows\System32is now in your path - Navigate back to your project folder and run
npm startagain—this should launch Expo without the error
Bonus Check
While your Node.js (v10.15.0) and npm (6.4.1) versions are a bit outdated, they should work with Expo 2.6.14. If the PATH fix doesn't resolve things, you could try updating Expo to a more recent version with npm install -g expo-cli, but start with the PATH fix first—it's the most likely culprit here.
内容的提问来源于stack exchange,提问作者roopesh

