错误!缺少脚本:"start"

npm ERR! Missing script: "start"

我是新手 js.Trying 反应 运行 一个简单的应用程序并收到此错误并且无法弄清楚出了什么问题

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\_logs22-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"
  }
}

发生这种情况是因为您的 package.json 文件中没有名为“start”的脚本。下面是一个 package.json 文件的示例,其中包含这样的脚本:

{
  "name": "your-project",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "start": "node main.js"
  },
  "author": "Muralidharan",
  "dependencies": {
  }
}

将此添加到您的 package.json

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

start 是触发 react-script 到 运行 项目所需的命令 构建、测试和弹出是您在开发过程中需要的其他命令

感谢所有回答问题的人,问题出在过时的版本上 所以我这样做是为了解决

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