【问题标题】:Getting error when npm start with React application使用 React 应用程序启动 npm 时出现错误
【发布时间】:2020-07-03 12:01:20
【问题描述】:

每当我使用npx create-react-app test 创建一个新的 React 文件夹时,我都会遇到这个问题。 npm start 不起作用并在终端中抛出此错误消息

> test@0.1.0 start C:\Users\franc\Desktop\test
> react-scripts start

i 「wds」: Project is running at http://192.168.56.1/
i 「wds」: webpack output is served from
i 「wds」: Content not from webpack is served from C:\Users\franc\Desktop\test\public
i 「wds」: 404s will fallback to /
Starting the development server...

events.js:288
      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! test@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test@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\franc\AppData\Roaming\npm-cache\_logs\2020-03-23T00_10_45_653Z-debug.log

有人知道怎么解决吗?

【问题讨论】:

    标签: node.js reactjs npm create-react-app npm-start


    【解决方案1】:

    查看你的 package.json 文件夹 test ./test/package.json 你会看到这样的东西:

      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
      },
    

    如果存在,请运行 npm run start 添加单词 run - 还要确保在创建应用程序后 cd 进入测试文件夹。

    【讨论】:

    • 您拥有的“脚本”部分与我的相同。此外,我确实确保我在正确的文件夹中,但 npm startnpm run start 都给了我同样的错误。
    • 尝试删除 node_modules 而不是 npm install
    【解决方案2】:

    我通过将C:\Windows\System32 添加到环境变量中的PATH 并重新启动系统解决了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-02
      • 1970-01-01
      • 1970-01-01
      • 2020-10-18
      • 2018-11-09
      • 2018-03-26
      • 2017-05-07
      相关资源
      最近更新 更多