我是反應 js 的新手。嘗試運行一個簡單的應用程式并收到此錯誤并且無法弄清楚出了什么問題
D:\React app\react-app1>npm start
npm ERR! Missing script: "start"
npm ERR!
npm ERR! Did you mean one of these?
npm ERR! npm star # Mark your favorite packages
npm ERR! npm stars # View packages marked as favorites
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Muralidharan\AppData\Local\npm-cache\_logs\2022-05-29T08_51_37_315Z-debug-0.log
這是 package.json 檔案
{
"name": "react-app1",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-scripts": "5.0.1"
}
}
uj5u.com熱心網友回復:
發生這種情況是因為您的 package.json 檔案中沒有名為“start”的腳本。以下是帶有此類腳本的 package.json 檔案的示例:
{
"name": "your-project",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "node main.js"
},
"author": "Muralidharan",
"dependencies": {
}
}
uj5u.com熱心網友回復:
將此添加到您的 package.json
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
},
start 是您需要觸發 react-script 來運行您的專案構建、測驗和彈出的命令是您在開發程序中需要的其他命令
uj5u.com熱心網友回復:
感謝所有回答問題的人,問題出在過時的版本上所以我這樣做是為了解決
1. npm uninstall -g create-react-app
2. npm install create-react-app ( v1.5.2 is outdated and no longer supported ??)
3. npx create-react-app react-app
4. cd react-app
5. npm start
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/482151.html
