typescript 尝试在package.json上安装npm时出现错误

wecizke3  于 2023-03-13  发布在  TypeScript
关注(0)|答案(1)|浏览(172)

我尝试用npm install来建立一个Angular项目,但是遇到了这些错误。我在mac上,试图打开一个相对较老的项目,这很可能是我遇到这些问题的原因。

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @angular-devkit/build-angular@15.2.2
npm ERR! Found: typescript@3.5.3
npm ERR! node_modules/typescript
npm ERR!   dev typescript@"~3.5.3" from the root project
npm ERR!   peer typescript@">=2.1.0 || >=2.1.0-dev || >=2.2.0-dev || >=2.3.0-dev || >=2.4.0-dev || >=2.5.0-dev || >=2.6.0-dev || >=2.7.0-dev || >=2.8.0-dev || >=2.9.0-dev || >=3.0.0-dev || >= 3.1.0-dev || >= 3.2.0-dev" from tslint@5.15.0
npm ERR!   node_modules/tslint
npm ERR!     dev tslint@"~5.15.0" from the root project
npm ERR!   1 more (tsutils)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer typescript@">=4.8.2 <5.0" from @angular-devkit/build-angular@15.2.2
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR!   dev @angular-devkit/build-angular@"^15.2.2" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: typescript@4.9.5
npm ERR! node_modules/typescript
npm ERR!   peer typescript@">=4.8.2 <5.0" from @angular-devkit/build-angular@15.2.2
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"^15.2.2" from the root project
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.

我尝试过--force--legacy-peer-deps,但它们都给予了我一些漏洞。我也尝试过降低节点版本,但没有效果。我查看了package.json版本,找到了“@types/node”:“~8.9.4”,从我那里我发现了这个项目的一个特定依赖项,并尝试降级到那个版本。所有这些都让它变得难以置信的慢,最终给我留下了错误。下面是package.json文件:

{
  "name": "client",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^15.2.2",
    "@angular/cdk": "^15.2.2",
    "@angular/common": "^15.2.2",
    "@angular/compiler": "^8.2.14",
    "@angular/core": "^8.2.14",
    "@angular/flex-layout": "^8.0.0-beta.27",
    "@angular/forms": "^15.2.2",
    "@angular/material": "^15.2.2",
    "@angular/platform-browser": "^15.2.2",
    "@angular/platform-browser-dynamic": "^15.2.2",
    "@angular/router": "^15.2.2",
    "apollo-angular": "^4.2.1",
    "apollo-angular-link-http": "^1.11.0",
    "apollo-cache-inmemory": "^1.6.6",
    "apollo-client": "^2.6.10",
    "apollo-link": "^1.2.14",
    "deep-copy-ts": "^0.5.0",
    "graphql": "^14.7.0",
    "graphql-tag": "^2.11.0",
    "hammerjs": "^2.0.8",
    "rxjs": "~6.4.0",
    "ts-deepcopy": "^0.1.4",
    "tslib": "^1.13.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^15.2.2",
    "@angular/cli": "^15.2.2",
    "@angular/compiler-cli": "^15.2.2",
    "@angular/language-service": "^8.2.14",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "^2.0.8",
    "@types/node": "~8.9.4",
    "codelyzer": "^0.0.28",
    "jasmine-core": "^3.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^6.4.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.5.4",
    "protractor": "^7.0.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  }
}

以下是我在终端运行“ng version”时的版本。我刚刚开始前端开发工作,所以希望能提供一些输入。
编辑:按照robert的建议,得到了以下错误。
尝试2次

x 1c 2d 1x

zzwlnbp8

zzwlnbp81#

这个问题是由于有一个Angular 的版本,但不是所有的npm包都支持当前版本和许多其他过时的功能。

npm install --force

它将从package.json下载所有包及其版本,并确保在使用时运行该项目

npm run start

仅下载指定版本的软件包

npm ci --force

要在安装了所有packaage.json后修复此问题,如果出现任何问题,请使用

npm install --legacy-peer-deps

相关问题