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

如何将react-scripts 5.0.1降级至4.0.3版本

对应报错信息

Invalid options object. Dev Server has been initialized using an options object that does not match the API schema
该报错由react-scripts 5.x版本与部分自定义devServer配置、旧版项目依赖的兼容性问题引发,将react-scripts从5.0.1降级到4.0.3是成熟可行的修复方案,具体操作步骤如下:

降级操作步骤
  • 第一步:卸载当前项目中已安装的高版本react-scripts
    根据使用的包管理器执行对应命令:
    npm用户执行:
    npm uninstall react-scripts
    
    yarn用户执行:
    yarn remove react-scripts
    
  • 第二步:安装指定4.0.3版本的react-scripts
    必须加精确安装参数,避免自动安装同大版本下的其他高版本导致修复失效:
    npm用户执行:
    npm install react-scripts@4.0.3 --save-exact
    
    yarn用户执行:
    yarn add react-scripts@4.0.3 --exact
    
  • 第三步:清理依赖缓存与残留文件,避免版本冲突
    1. 手动删除项目根目录下的node_modules文件夹,以及对应包管理器的锁文件:npm用户删除package-lock.json,yarn用户删除yarn.lock
    2. 执行缓存清理命令:
      npm用户执行:
      npm cache clean --force
      
      yarn用户执行:
      yarn cache clean
      
    3. 重新安装全量项目依赖:
      npm用户执行:
      npm install
      
      yarn用户执行:
      yarn
      
  • 第四步:验证修复效果
    执行项目启动命令:
    # npm用户
    npm start
    
    # yarn用户
    yarn start
    
    正常情况下之前的devServer初始化报错会消失,项目可以正常启动开发服务。

注意:如果项目之前针对react-scripts 5.x做过devServer相关的自定义配置,降级完成后需要对照react-scripts 4.0.3对应的配置规则做适配检查,避免出现其他配置不兼容问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.26 23:27:35