create-react-app安装,但无法通过“开始”运行

时间:2019-06-14 14:06:16

标签: javascript reactjs create-react-app

在带有NodeJS便携式版本12.4.0的Windows 10上(我在公司计算机上,无权安装NodeJS)。

当我运行npx create-react-app myApp时,它运行正常,没有错误。我应该提到我有一个现有的应用程序(创建于几个月前),该应用程序仍可以在同一台计算机上正常运行,但是使用了较旧版本的react-scripts。

运行npm run start时,出现此错误:


events.js:177
      throw er; // Unhandled 'error' event
      ^

Error: spawn cmd ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
    at onErrorNT (internal/child_process.js:456:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:9)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)
    at onErrorNT (internal/child_process.js:456:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:9) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn cmd',
  path: 'cmd',
  spawnargs: [ '/c', 'start', '""', '/b', 'http://localhost:3000/' ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! req@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the req@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.```




2 个答案:

答案 0 :(得分:1)

使用react-scripts@3.1.8时,环境变量似乎有问题 参见:https://github.com/facebook/create-react-app/issues/6985

只需降级您的反应脚本的版本,它就可以工作:

create-react-app my-app
cd my-app
npm install react-scripts@2.1.8
npm start

答案 1 :(得分:0)

我建议处理该错误。如果您需要比这更具体的内容,似乎我们需要查看代码。

您还可以使用流程管理器(例如PM2)在机器人崩溃时自动重启。