Azure Pipeline执行npm ci遇依赖冲突报错,本地运行正常
Azure Pipeline中npm ci任务失败问题
问题场景
Azure Pipeline执行npm ci任务时持续失败,但本地运行该命令完全正常。
失败的Pipeline任务配置
- task: Npm@1 displayName: "React: web client - npm ci" inputs: command: "ci" workingDir: "web/client"
任务错误输出
npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: @progress/kendo-react-animation@7.0.2 npm ERR! Found: react-transition-group@4.4.5 npm ERR! node_modules/react-transition-group npm ERR! react-transition-group@"^4.4.5" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer react-transition-group@"4.4.2" from @progress/kendo-react-animation@7.0.2 npm ERR! node_modules/@progress/kendo-react-animation npm ERR! @progress/kendo-react-animation@"^7.0.2" from the root project npm ERR! peer @progress/kendo-react-animation@"7.0.2" from @progress/kendo-react-data-tools@7.0.2 npm ERR! node_modules/@progress/kendo-react-data-tools npm ERR! @progress/kendo-react-data-tools@"^7.0.2" from the root project npm ERR! 5 more (@progress/kendo-react-gantt, ...) npm ERR! 5 more (@progress/kendo-react-grid, ...) npm ERR! npm ERR! Conflicting peer dependency: react-transition-group@4.4.2 npm ERR! node_modules/react-transition-group npm ERR! peer react-transition-group@"4.4.2" from @progress/kendo-react-animation@7.0.2 npm ERR! node_modules/@progress/kendo-react-animation npm ERR! @progress/kendo-react-animation@"^7.0.2" from the root project npm ERR! peer @progress/kendo-react-animation@"7.0.2" from @progress/kendo-react-data-tools@7.0.2 npm ERR! node_modules/@progress/kendo-react-data-tools npm ERR! @progress/kendo-react-data-tools@"^7.0.2" from the root project npm ERR! 5 more (@progress/kendo-react-gantt, ...) npm ERR! 5 more (@progress/kendo-react-grid, ...) npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! npm ERR! For a full report see: npm ERR! C:\npm\cache\_logs\2024-01-10T21_56_36_903Z-eresolve-report.txt
环境对比
- 本地PC:Node.js 18.19.0,npm 10.2.5
- Azure Pipeline:Node.js 18.19.0 x64,npm 10.2.3
解决方案建议
方案1:统一npm版本
将Azure Pipeline中的npm版本升级到与本地一致的10.2.5,消除版本差异导致的依赖解析行为不同。可在Pipeline中添加以下任务:
- task: NodeTool@0 inputs: versionSpec: '18.19.0' displayName: 'Install Node.js' - script: npm install -g npm@10.2.5 displayName: 'Upgrade npm to 10.2.5'
方案2:添加依赖解析参数
修改npm ci命令,添加--legacy-peer-deps参数跳过peer依赖冲突检查,对齐本地解析行为:
- task: Npm@1 displayName: "React: web client - npm ci" inputs: command: "ci" workingDir: "web/client" arguments: '--legacy-peer-deps'
方案3:修复依赖版本冲突
调整package.json中的react-transition-group版本为4.4.2,匹配@progress/kendo-react-animation@7.0.2的peer依赖要求,重新生成package-lock.json并提交:
{ "dependencies": { "react-transition-group": "4.4.2" } }
内容的提问来源于stack exchange,提问作者GettingStarted
相关产品推荐
相关产品推荐

