簡體   English   中英

對 React 應用程序使用“npm start 命令”時出現錯誤

[英]I am getting error while using "npm start command for React application

我是新手,這是我的第一個應用程序。
我已經安裝了最新版本的節點 npm/npx。
我使用“create-react-app my-app”創建了一個目錄。
之后,當我進入目錄並輸入“npm start”時,出現以下錯誤。 請幫忙


C:\Users\admin\my-app>npm start

> my-app@0.1.0 start C:\Users\admin\my-app
> react-scripts start

Starting the development server...

events.js:288
     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! my-app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-app@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\admin\AppData\Roaming\npm-cache\_logs\2020-04-12T15_19_48_491Z-debug.log

這是我的package.json內容

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

正如一些人建議的那樣,我刪除了我的node modules文件夾,然后進行了npm update ,然后npm install ,但我仍然遇到同樣的錯誤。 任何幫助將不勝感激

我以前見過這個。 嘗試刪除你的node_modules文件夾,然后運行npm update然后npm install

如果這不起作用,其他論壇有一些答案:

  • 一些 windows 用戶表示將 System32 添加到環境變量有幫助:

轉到Control Panel > SystemSecurity > System > Advanced system settings > Enviroment variables並將系統變量設置為路徑C:\Windows\System32\並重新啟動系統。

  • 最壞的情況:將react-scripts降級到 2.1.8:

npm install react-scripts@2.1.8

暫無
暫無

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

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