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

Angular项目一台机器npm install正常,另一台遇依赖冲突错误

Angular项目npm install出现ERESOLVE依赖冲突(@angular/cdk@^12.1.0)

我开发一个Angular项目已有数月,在A机器上运行完全正常(仅偶尔因拼写失误出错)。下月将外出,想在笔记本上运行该项目,已安装好Node、Angular等环境。从Git仓库拉取源码后执行npm i安装node_modules,却出现ERESOLVE依赖冲突错误,涉及@angular/cdk@"^12.1.0"。错误提示需修复上游依赖冲突,或使用--force/--legacy-peer-deps重试。

注:MY_USER_FOLDER为化名,已隐去真实用户名。日志文件较大,如需可提供。

以下是项目的package.json:

{"name": "ngx-admin","version": "10.0.0","license": "MIT","repository": {"type": "git","url": "git+https://github.com/akveo/ngx-admin.git"},"bugs": {"url": "https://github.com/akveo/ngx-admin/issues"},"scripts": {"ng": "ng","conventional-changelog": "conventional-changelog","start": "ng serve","build": "ng build","build:prod": "npm run build -- --configuration production --aot","test": "ng test","test:coverage": "rimraf coverage && npm run test -- --code-coverage","lint": "ng lint","lint:fix": "ng lint ngx-admin-demo --fix","lint:styles": "stylelint ./src/**/*.scss","lint:ci": "npm run lint && npm run lint:styles","pree2e": "webdriver-manager update --standalone false --gecko false","e2e": "ng e2e","docs": "compodoc -p src/tsconfig.app.json -d docs","docs:serve": "compodoc -p src/tsconfig.app.json -d docs -s","prepush": "npm run lint:ci","release:changelog": "npm run conventional-changelog -- -p angular -i CHANGELOG.md -s","postinstall": "ngcc --properties es2015 es5 browser module main --first-only --create-ivy-entry-points --tsconfig \"../src/tsconfig.app.json\""},"dependencies": {"@angular/animations": "^14.2.12","@angular/cdk": "^12.1.0","@angular/common": "^14.2.12","@angular/compiler": "^14.2.12","@angular/core": "^14.2.12","@angular/forms": "^14.2.12","@angular/google-maps": "^12.2.13","@angular/platform-browser": "^14.2.12","@angular/platform-browser-dynamic": "^14.2.12","@angular/router": "^14.2.12","@asymmetrik/ngx-leaflet": "3.0.1","@nebular/auth": "10.0.0","@nebular/eva-icons": "10.0.0","@nebular/security": "10.0.0","@nebular/theme": "10.0.0","@swimlane/ngx-charts": "^14.0.0","angular2-chartjs": "0.4.1","bootstrap": "4.3.1","chart.js": "2.7.1","ckeditor": "4.7.3","classlist.js": "1.1.20150312","core-js": "2.5.1","echarts": "^4.9.0","eva-icons": "^1.1.3","intl": "1.2.5","ionicons": "2.0.1","leaflet": "1.2.0","monaco-editor": "^0.24.0","nebular-icons": "1.1.0","ng2-ckeditor": "~1.2.9","ng2-completer": "^9.0.1","ng2-smart-table": "^1.6.0","ngx-echarts": "^4.2.2","ngx-monaco-editor": "^12.0.0","node-sass": "^7.0.0","normalize.css": "6.0.0","pace-js": "1.0.2","roboto-fontface": "0.8.0","rxjs": "6.6.2","rxjs-compat": "6.3.0","socicon": "3.0.5","style-loader": "^1.3.0","tinymce": "4.5.7","tslib": "^2.3.1","typeface-exo": "0.0.22","web-animations-js": "^2.3.2","zone.js": "~0.11.4"},"devDependencies": {"@angular-devkit/build-angular": "^14.2.10","@angular-eslint/builder": "14.4.0","@angular-eslint/eslint-plugin": "14.4.0","@angular-eslint/eslint-plugin-template": "14.4.0","@angular-eslint/schematics": "14.4.0","@angular-eslint/template-parser": "14.4.0","@angular/cli": "^14.2.10","@angular/compiler-cli": "^14.2.12","@angular/language-service": "14.2.12","@compodoc/compodoc": "1.0.1","@fortawesome/fontawesome-free": "^5.2.0","@types/d3-color": "1.0.5","@types/jasmine": "~3.3.0","@types/jasminewd2": "2.0.3","@types/leaflet": "1.2.3","@types/node": "^12.12.70","@typescript-eslint/eslint-plugin": "^5.36.2","@typescript-eslint/parser": "^5.36.2","codelyzer": "^6.0.2","conventional-changelog-cli": "1.3.4","eslint": "^8.23.0","husky": "0.13.3","jasmine-core": "~3.6.0","jasmine-spec-reporter": "~5.0.0","karma": "~6.3.19","karma-chrome-launcher": "~3.1.1","karma-cli": "1.0.1","karma-coverage-istanbul-reporter": "~3.0.2","karma-jasmine": "~4.0.2","karma-jasmine-html-reporter": "^1.7.0","npm-run-all": "4.0.2","protractor": "~7.0.0","rimraf": "2.6.1","stylelint": "7.13.0","ts-node": "3.2.2","tslint": "~6.1.0","tslint-language-service": "^0.9.9","typescript": "~4.6.4"}}

已尝试以下方法但均无效:

  • 搜索相关解决方案
  • 降级/升级Node和Angular CLI
  • 使用npm i --force和npm i --legacy-peer-deps(仍报错)
  • 更新错误中提及的单个包
  • 查阅Stack Overflow相关问题(未找到有效方案)

解决方案

1. 统一Angular CDK与核心框架版本

项目中Angular核心包(如@angular/core)是14.2.12版本,但@angular/cdk停留在12.1.0,版本差距过大导致依赖冲突。将@angular/cdk和@angular/google-maps升级到与Angular核心一致的14.x版本:

"@angular/cdk": "^14.2.12",
"@angular/google-maps": "^14.2.12"

2. 清理缓存并重新安装

执行以下命令彻底清理缓存和旧依赖:

rm -rf node_modules package-lock.json
npm cache clean --force
npm install

3. 检查其他依赖的版本兼容性

  • ngx-monaco-editor当前是12.0.0,建议升级到适配Angular 14的版本(如^14.0.0)
  • 确认@nebular/*包(10.0.0)是否兼容Angular 14,若存在兼容性问题,可考虑升级Nebular到对应版本或回退Angular到12.x(前者更利于长期维护)

4. 锁定Node版本

确保笔记本上的Node版本与A机器一致(通过node -v查看),不一致的话用nvm等工具切换到相同版本,避免因Node版本差异导致的依赖解析问题。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 10:23:14