簡體   English   中英

使用 React 應用程序啟動 npm 時出錯

[英]Getting error when npm start with React application

每當我使用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

有人知道如何解決嗎?

看看你的 package.json 文件夾 test ./test/package.json你會看到這樣的:

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

如果在那里 run npm run start添加單詞run - 還要確保在創建應用程序后 cd 進入測試文件夾。

我通過將C:\\Windows\\System32到環境變量中的 PATH 並重新啟動系統來解決我的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM