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

使用create-react-app创建项目时遭遇依赖冲突错误求助

解决create-react-app 5.0.1创建项目时React 19与@testing-library/react的依赖冲突

问题背景

使用create-react-app 5.0.1、Node.js v22.12.0、npm 10.9.0创建新项目时,触发ERESOLVE依赖树冲突错误:自动安装的react@19.0.0与@testing-library/react@13.4.0要求的peer依赖react@^18.0.0不兼容。

解决方案

1. 指定React 18版本创建项目

直接在创建命令中强制指定兼容的React 18版本,匹配@testing-library/react@13.4.0的peer依赖要求:

# JavaScript项目
npx create-react-app my-app --override react@^18.2.0 react-dom@^18.2.0

# TypeScript项目
npx create-react-app my-app --template typescript --override react@^18.2.0 react-dom@^18.2.0

2. 升级@testing-library/react至兼容React 19的版本

@testing-library/react v15.x及以上版本已支持React 19,可通过以下方式升级:

  • 修改项目package.json中@testing-library/react的版本为^15.0.0,然后执行:
    npm install
    
  • 或者直接在项目目录下运行升级命令:
    npm install @testing-library/react@latest
    

3. 使用npm的legacy-peer-deps参数绕过检查(临时方案)

此方法仅临时跳过peer依赖冲突检查,不推荐长期使用:

npx create-react-app my-app --legacy-peer-deps

4. 降级Node.js至LTS版本

create-react-app 5.0.1发布时Node.js 22尚未推出,存在版本适配问题,可降级至Node.js 18.x或20.x(LTS版本),重新创建项目即可解决依赖冲突。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 19:27:05