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

创建React应用时反复出现相同错误,package.json未生成scripts字段

报错截图

临时解决方法

直接手动在你现有的package.json中补充scripts字段即可正常使用,修改后的完整文件内容如下:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "cra-template": "1.1.2",
    "postinstall-js": "^0.7.1",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-scripts": "4.0.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  }
}

修改保存后执行npm start就能正常启动项目。

彻底解决该问题的方案

  • 先卸载本地全局安装的旧版create-react-app:npm uninstall -g create-react-app,后续创建React项目统一使用npx create-react-app 项目名的命令,直接拉取最新版本的模板,避免本地版本兼容问题。
  • 要是卸载后重新创建仍有问题,执行npm cache clean --force清理npm损坏的缓存后再重试。
  • 网络不佳的情况下,可以指定国内镜像源创建项目:npx create-react-app 项目名 --registry https://registry.npmmirror.com。

内容的提问来源于stack exchange,提问作者Rachit

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.09 11:45:00