You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何npm start命令无法正常运行?提示缺少start脚本

React项目npm start报错:Missing script: "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: C:\Users\kikaj\AppData\Local\npm-cache\_logs\2023-10-24T03_13_20_595Z-debug-0.log

解决步骤

  • 确认当前工作目录
    必须在React项目的根目录下执行npm start,根目录需包含package.json文件。用dir(Windows)或ls(Mac/Linux)命令查看当前目录,确认文件存在。

  • 检查package.json的scripts配置
    打开package.json,查看scripts字段是否包含start命令。正常React项目的配置如下:

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

    若缺少start脚本,手动添加上述内容(需确保已安装react-scripts)。

  • 重新安装依赖
    若配置正常仍报错,可能是依赖不完整。执行以下命令:

    # Windows系统
    rmdir /s /q node_modules && del package-lock.json
    npm install
    
    # Mac/Linux系统
    rm -rf node_modules package-lock.json
    npm install
    

    重新安装后再尝试npm start。

  • 补装react-scripts依赖
    若项目不是通过npx create-react-app创建,可能缺少react-scripts。执行命令安装:

    npm install react-scripts --save
    

    安装完成后添加start脚本到package.json中。

内容的提问来源于stack exchange,提问作者Thiago Brandão

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 19:20:00