第一次设置 React 时出错 (event.js:287)

Error while setting up react for the first time (event.js:287)

error from cmd

我是第一次尝试安装 React,但每当我 运行 "npm start"[ 时总是会出现错误=24=]

    C:\react\reactjs>npm install -g yarn
C:\Users\UNCLE  BIGBAY\AppData\Roaming\npm\yarnpkg -> C:\Users\UNCLE  BIGBAY\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js
C:\Users\UNCLE  BIGBAY\AppData\Roaming\npm\yarn -> C:\Users\UNCLE  BIGBAY\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js
+ yarn@1.22.4
updated 1 package in 2.163s

C:\react\reactjs>npm start

> reactjs@0.1.0 start C:\react\reactjs
> react-scripts start

Starting the development server...

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

Error: spawn cmd ENOENT
[90m    at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)[39m
[90m    at onErrorNT (internal/child_process.js:469:16)[39m
[90m    at processTicksAndRejections (internal/process/task_queues.js:84:21)[39m
Emitted 'error' event on ChildProcess instance at:
[90m    at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)[39m
[90m    at onErrorNT (internal/child_process.js:469:16)[39m
[90m    at processTicksAndRejections (internal/process/task_queues.js:84:21)[39m {
  errno: [32m'ENOENT'[39m,
  code: [32m'ENOENT'[39m,
  syscall: [32m'spawn cmd'[39m,
  path: [32m'cmd'[39m,
  spawnargs: [ [32m'/s'[39m, [32m'/c'[39m, [32m'start'[39m, [32m'""'[39m, [32m'/b'[39m, [32m'"http://localhost:3000"'[39m ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactjs@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactjs@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\UNCLE  BIGBAY\AppData\Roaming\npm-cache\_logs20-04-23T00_06_27_219Z-debug.log

C:\react\reactjs>

我试过更新 yarn 甚至重新安装它

我猜您正在尝试使用 create-react-app

您是否使用 npx 进行设置?

npx create-react-app joakims-app
cd joakims-app
npm start

顺便说一句:看起来你是 运行 windows - 不知道这是否有任何帮助 https://makandracards.com/reactjs-quick/52419-install-reactjs-windows

我遇到了同样的问题。我删除了 node_modules 文件夹并使用以下命令重新安装:

npm install

之后一切正常。

我在这里找到解决方案https://gitmemory.com/issue/facebook/create-react-app/6985/491604318

请将 C:\Windows\System32 添加到环境变量路径并重启设备后尝试。

您可以借助此脚本降级并将其写入您的终端,然后一切正常:

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

这绝对行得通。谢谢 ))