首页 > 解决方案 > 即使正确的 npm/node 版本,Create-react-app 也不能在“npm start”工作

问题描述

  1. 我正在学习本教程的反应。我收到一个关于没有启动脚本的错误,使用我的文本编辑器添加到 package.json 文件中。现在我真的不知道如何解决我的新错误。
  2. 更新了我的 package-json 文件,卸载并重新安装了 create-react-app,创建了新的 react-app 文件夹,读取了堆栈溢出。使用“npx react-scripts start”手动启动它。
  3. 我的 npm -v (6.7.0) 和 node -v (12.16.0)

    react-app 的文件目录树

    • 节点模块
      • 使用 create-react-app 创建文件夹时添加的文件夹列表
    • 上市
      • favicon.ico
      • 索引.html
      • 清单.json
    • 源代码

      • index.js
    • .gitignore
    • 包.json
    • 包-lock.json
    • 自述文件.md

错误:

circulating@CLAPP-T460-22 MINGW64 ~/Desktop/react-app (master)
$ npm start

> react-app@1.1.0 start C:\Users\circulating\Desktop\react-app
> react-scripts start


i 「wds」: Project is running at http://192.168.1.16/
i 「wds」: webpack output is served from
i 「wds」: Content not from webpack is served from C:\Users\circulating\Desktop\re                                                                                                                act-app\public
i 「wds」: 404s will fallback to /
Starting the development server...

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

Error: spawn cmd 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 cmd',
  path: 'cmd',
  spawnargs: [ '/s', '/c', 'start', '""', '/b', '"http://localhost:3000/"' ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-app@1.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-app@1.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional log                                                                                                                ging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\circulating\AppData\Roaming\npm-cache\_logs\2020-06-07T01_                                                                                                                12_36_919Z-debug.log

标签: node.jsreactjsnpmcreate-react-app

解决方案


将 C:\Windows\System32 添加到全局 PATH 环境变量中。

或者

使用不同的 react 脚本版本重新安装你的 npm。只需在命令中转到您的文件夹并像这样重新安装: npm install react-scripts@2.1.8 npm start


推荐阅读