首页 > 解决方案 > 尝试朗姆酒 npm start 命令时出错

问题描述

我正在尝试创建一个我已经运行的反应项目,npx create-react-app my-app但是cd my-app当我 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 然后我再次安装它但同样的问题仍然发生

标签: reactjsnpmcmdnode-modulesnpm-start

解决方案


我找到了一些可能的解决方案。似乎您正在使用 powershell,首先检查您的 PATH 中是否将其作为 %SystemRoot%/system32/WindowsPowerShell/v1.0。之后以管理员身份打开powershell并编写

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force

如果powershell出现问题,它应该会有所帮助。或者,有时可能是 cra 开发服务器尝试打开 Web 浏览器时出错。github上有人说这对他有帮助:

此错误源于 CRA 尝试打开您的浏览器:为了跳过打开浏览器,添加 BROWSER=none 到您的 .env 或 .env.local 文件

另一种方法是使用这些命令降级项目的反应脚本

npm install react-scripts@2.1.8
npm start

推荐阅读