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

从tsLint迁移至ESLint时出现npm依赖冲突错误

解决Angular 15迁移ESLint时的npm依赖冲突问题

问题场景

在Angular 15.0.4项目中执行ng add @angular-eslint/schematics从TSLint迁移至ESLint时,触发npm依赖冲突错误:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: codelyzer@0.0.28
npm ERR! Found: tslint@6.1.3
npm ERR! node_modules/tslint
npm ERR!   dev tslint@"~6.1.3" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer tslint@"^3.9.0" from codelyzer@0.0.28
npm ERR! node_modules/codelyzer
npm ERR!   dev codelyzer@"^0.0.28" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: tslint@3.15.1
npm ERR! node_modules/tslint
npm ERR!   peer tslint@"^3.9.0" from codelyzer@0.0.28
npm ERR!   node_modules/codelyzer
npm ERR!     dev codelyzer@"^0.0.28" 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.

项目package.json内容:

{
  "name": "EDUSupport",
  "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.0.4",
    "@angular/cdk": "^15.0.3",
    "@angular/common": "^15.0.4",
    "@angular/compiler": "^15.0.4",
    "@angular/core": "^15.0.4",
    "@angular/forms": "^15.0.4",
    "@angular/material": "^15.0.3",
    "@angular/platform-browser": "^15.0.4",
    "@angular/platform-browser-dynamic": "^15.0.4",
    "@angular/router": "^15.0.4",
    "@nativescript/schematics": "^10.1.0",
    "@nguniversal/common": "^15.2.0",
    "core-js": "^2.5.4",
    "loader-utils": "^3.2.1",
    "material-icons-font": "^2.1.0",
    "ngx-avatars": "^1.5.0",
    "rxjs": "~6.6.3",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^15.0.4",
    "@angular/cli": "^15.0.4",
    "@angular/compiler-cli": "^15.0.4",
    "@angular/language-service": "^15.0.4",
    "@types/jasmine": "~3.6.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^0.0.28",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~6.3.17",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "sass": "^1.57.1",
    "ts-node": "~7.0.0",
    "tslint": "~6.1.3",
    "typescript": "~4.8.4"
  }
}

已尝试但无效的操作:删除node_modules后重新npm install、升级Angular至16、使用--legacy-peer-deps安装、降级全局CLI并重装。

解决方案

1. 移除冲突的TSLint相关依赖

冲突根源是codelyzer@0.0.28(TSLint规则库)仅兼容tslint@^3.9.0,但项目使用tslint@6.1.3,且迁移ESLint后无需TSLint及codelyzer,直接卸载:

npm uninstall --save-dev codelyzer tslint

2. 清理依赖残留

  • 删除本地依赖文件夹和锁文件:
    # macOS/Linux
    rm -rf node_modules package-lock.json
    # Windows
    rd /s /q node_modules && del package-lock.json
    
  • 清理npm缓存:
    npm cache clean --force
    

3. 重新安装基础依赖

npm install

此时依赖冲突已消除,安装过程不会再出现ERESOLVE错误。

4. 重新执行ESLint迁移命令

ng add @angular-eslint/schematics

该命令会自动配置ESLint相关依赖、替换项目中的TSLint配置文件,并更新package.json中的lint脚本为ESLint执行命令。

5. 验证迁移结果

执行lint命令确认ESLint正常工作:

npm run lint

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 16:22:05