我试图创建一个我先运行npx create-react-app my-app
然后运行cd my-app
的react项目,但是当我运行npm start
时
已显示此错误:
> my-app@0.1.0 start C:\Users\USER\my-app
> react-scripts start
i 「wds」: Project is running at http://192.168.137.1/
i 「wds」: webpack output is served from
i 「wds」: Content not from webpack is served from C:\Users\HAMOOD\my-app\public
i 「wds」: 404s will fallback to /
Starting the development server...
events.js:292
throw er; // Unhandled 'error' event
^
Error: spawn powershell ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn powershell',
path: 'powershell',
spawnargs: [
'-NoProfile',
'-NonInteractive',
'–ExecutionPolicy',
'Bypass',
'-EncodedCommand',
'UwB0AGEAcgB0ACAAIgBgACIAaAB0AHQAcAA6AC8ALwBsAG8AYwBhAGwAaABvAHMAdAA6ADMAMAAwADAAYAAiACIA'
]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\HAMOOD\AppData\Roaming\npm-cache\_logs\2020-08-23T13_09_04_330Z-debug.log
我试图删除node_modules,然后再次安装它,但是仍然存在相同的问题
答案 0 :(得分:10)
我找到了一些可能的解决方案。似乎您正在使用Powershell,请首先检查您的Powershell是否为%SystemRoot%/ system32 / WindowsPowerShell / v1.0。之后,以管理员身份打开powershell并编写
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
如果powershell存在问题,它应该会有所帮助。或者,有时在cra dev服务器尝试打开Web浏览器时可能是错误。 github上有人说这对他有帮助:
此错误源于CRA尝试打开浏览器的事实: 为了跳过打开浏览器,添加
BROWSER=none
到您的.env或.env.local文件
另一种方法是使用这些命令降级项目的反应脚本
npm install react-scripts@2.1.8
npm start
答案 1 :(得分:2)
转到>控制面板\系统和安全性\系统\高级系统设置\环境变量,然后设置系统变量路径C:\ Windows \ System32 \变量,然后重新启动系统。
答案 2 :(得分:2)