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

Angular项目中npm install执行失败,请求技术支持

解决npm install时的ERESOLVE依赖冲突问题

核心解决方案

方案1:修正TypeScript版本到兼容范围(推荐)

你的项目中typescript@~4.9.4与@angular/compiler-cli@15.0.4的peer依赖要求(>=4.8.2 <4.9)冲突。修改package.json的devDependencies部分,将TypeScript版本调整到符合要求的范围:

"devDependencies": {
  // 保留其他依赖不变
  "typescript": "~4.8.4"
}

执行以下命令重新安装:

# Windows环境
Remove-Item -Recurse -Force node_modules
Remove-Item package-lock.json
npm cache clean --force
npm install

方案2:使用npm兼容模式(临时替代)

如果暂时不想调整版本,可以通过--legacy-peer-deps参数跳过peer依赖检查:

npm install --legacy-peer-deps

⚠️ 注意:此方法会忽略peer依赖冲突,可能导致后续构建或运行时出现兼容性问题,仅建议作为临时方案。


问题详情

执行npm install时出现如下错误:

PS D:\t> npm install
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: public_services@1.0.0
npm ERR! Found: typescript@4.9.4
npm ERR! node_modules/typescript
npm ERR!   dev typescript@"~4.9.4" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer typescript@">=4.8.2 <4.9" from @angular/compiler-cli@15.0.4
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   dev @angular/compiler-cli@"~15.0.4" from the root project
npm ERR!   peer @angular/compiler-cli@"15.0.4" from @angular/localize@15.0.4
npm ERR!   node_modules/@angular/localize
npm ERR!     dev @angular/localize@"^15.0.4" from the root project
npm ERR!     1 more (@ng-bootstrap/ng-bootstrap)
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! See C:\Users\sayed.hussainullah\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\sayed.hussainullah\AppData\Local\npm-cache\_logs\2023-01-11T06_57_30_299Z-debug-0.log

全局Angular版本信息

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 15.0.5
Node: 16.16.0
Package Manager: npm 8.17.0
OS: win32 x64

Angular:
...

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1500.5 (cli-only)
@angular-devkit/core         15.0.5 (cli-only)
@angular-devkit/schematics   15.0.5 (cli-only)
@schematics/angular          15.0.5 (cli-only)

项目package.json内容

{
    "name": "public_services",
    "version": "1.0.0",
    "license": "",
    "scripts": {
        "ng": "ng",
        "start": "ng serve",
        "build": "ng build",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e"
    },
    "private": true,
    "dependencies": {
        "@angular/animations": "~15.0.4",
        "@angular/cdk": "^15.0.4",
        "@angular/common": "~15.0.4",
        "@angular/compiler": "~15.0.4",
        "@angular/core": "~15.0.4",
        "@angular/forms": "~15.0.4",
        "@angular/platform-browser": "~15.0.4",
        "@angular/platform-browser-dynamic": "~15.0.4",
        "@angular/router": "15.0.4",
        "@fortawesome/angular-fontawesome": "^0.12.1",
        "@fortawesome/fontawesome-svg-core": "^6.2.1",
        "@fortawesome/free-brands-svg-icons": "^6.2.1",
        "@fortawesome/free-regular-svg-icons": "^6.2.1",
        "@fortawesome/free-solid-svg-icons": "^6.2.1",
        "@ng-bootstrap/ng-bootstrap": "14.0.1",
        "@ng-select/ng-select": "^10.0.3",
        "@ngx-translate/core": "^14.0.0",
        "@ngx-translate/http-loader": "7.0.0",
        "@swimlane/ngx-datatable": "^20.1.0",
        "angular-archwizard": "7.0.0",
        "angular-feather": "^6.5.0",
        "bootstrap": "5.2.3",
        "chart.js": "^4.1.2",
        "classlist.js": "1.1.20150312",
        "core-js": "3.27.1",
        "date-fns": "2.29.3",
        "gulp": "4.0.2",
        "hopscotch": "0.3.1",
        "intl": "1.2.5",
        "moment": "2.29.4",
        "ng-lazyload-image": "^9.1.3",
        "ng2-charts": "^4.1.1",
        "ng2-file-upload": "3.0.0",
        "ng2-img-cropper": "0.9.0",
        "ng2-jalali-date-picker": "^2.2.8",
        "ngx-bootstrap": "^10.2.0",
        "ngx-chips": "3.0.0",
        "ngx-datatable": "^1.0.3",
        "ngx-dropzone-wrapper": "^13.0.0",
        "ngx-perfect-scrollbar": "^7.2.1",
        "ngx-toastr": "16.0.2",
        "node-sass": "^8.0.0",
        "nouislider": "15.6.1",
        "prismjs": "1.29.0",
        "resize-observer-polyfill": "1.5.1",
        "rxjs": "7.8.0",
        "screenfull": "6.0.2",
        "sweetalert2": "11.6.16",
        "tslib": "^2.4.1",
        "web-animations-js": "^2.3.2",
        "xlsx": "^0.18.5",
        "zone.js": "~0.12.0"
    },
    "devDependencies": {
        "@angular-devkit/build-angular": "~15.0.5",
        "@angular/cli": "~15.0.5",
        "@angular/compiler-cli": "~15.0.4",
        "@angular/language-service": "~15.0.4",
        "@angular/localize": "^15.0.4",
        "@types/core-js": "2.5.5",
        "@types/jasmine": "^4.3.1",
        "@types/jasminewd2": "~2.0.10",
        "@types/jquery": "^3.5.16",
        "@types/node": "^18.11.18",
        "codelyzer": "^6.0.2",
        "jasmine-core": "~4.5.0",
        "jasmine-spec-reporter": "~7.0.0",
        "karma": "~6.4.1",
        "karma-chrome-launcher": "~3.1.1",
        "karma-cli": "~2.0.0",
        "karma-coverage-istanbul-reporter": "~3.0.3",
        "karma-jasmine": "~5.1.0",
        "karma-jasmine-html-reporter": "^2.0.0",
        "protractor": "~7.0.0",
        "rxjs-compat": "6.6.7",
        "ts-node": "~10.9.1",
        "tslint": "~6.1.0",
        "typescript": "~4.9.4"

    }
}

已尝试的无效方法

  • 删除node_modules文件夹
  • 清理npm缓存
  • 卸载并重装低版本Node.js
  • 安装msbuild-tools

内容的提问来源于stack exchange,提问作者Sayed Hussainullah Sadat

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 14:20:28