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

Angular14升级后执行ng lint触发Node未处理Promise拒绝警告

解决Angular 14升级后ng lint出现未处理Promise拒绝警告的问题

问题说明

将应用从Angular 13升级到14后,安装最新版ESLint并执行ng lint命令时,出现以下Node警告:

(node:15376) UnhandledPromiseRejectionWarning: #
(Use node --trace-warnings ... to show where the warning was created)
(node:15376) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:15376) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

目前仅知道降级回Angular 13可规避问题,现寻求其他解决方案,当前devDependencies配置如下:

"devDependencies": {
    "@angular-devkit/build-angular": "^14.2.1",
    "@angular-eslint/builder": "14.0.3",
    "@angular-eslint/eslint-plugin": "14.0.3",
    "@angular-eslint/eslint-plugin-template": "14.0.3",
    "@angular-eslint/schematics": "14.0.3",
    "@angular-eslint/template-parser": "14.0.3",
    "@angular/cli": "^14.2.1",
    "@angular/compiler-cli": "^14.2.0",
    "@angular/language-service": "^14.2.0",
    "@ngxs/devtools-plugin": "~3.7.1",
    "@progress/kendo-licensing": "~1.2.2",
    "@types/lodash": "~4.14.168",
    "@typescript-eslint/eslint-plugin": "5.29.0",
    "@typescript-eslint/parser": "5.29.0",
    "@webcomponents/custom-elements": "^1.4.3",
    "eslint": "^8.18.0",
    "eslint-plugin-deprecation": "^1.3.2",
    "typescript": "^4.6.4"
  }

可行解决方案

1. 对齐@angular-eslint包与Angular核心版本

你的@angular-eslint系列包版本为14.0.3,但Angular核心包已升级到14.2.1,版本不匹配可能引发内部Promise处理异常。执行以下命令将所有@angular-eslint包升级到Angular 14对应的最新兼容版本:

npm install @angular-eslint/builder@14.2.0 @angular-eslint/eslint-plugin@14.2.0 @angular-eslint/eslint-plugin-template@14.2.0 @angular-eslint/schematics@14.2.0 @angular-eslint/template-parser@14.2.0 --save-dev

若使用yarn则执行:

yarn add @angular-eslint/builder@14.2.0 @angular-eslint/eslint-plugin@14.2.0 @angular-eslint/eslint-plugin-template@14.2.0 @angular-eslint/schematics@14.2.0 @angular-eslint/template-parser@14.2.0 --dev

2. 排查ESLint插件兼容性

eslint-plugin-deprecation 1.3.2版本可能与ESLint 8.18.0存在兼容性问题,先尝试更新该插件到最新版:

npm install eslint-plugin-deprecation@latest --save-dev

若更新后问题仍存在,可临时在.eslintrc.json中移除deprecation插件配置,再执行ng lint测试警告是否消失。

3. 启用严格模式定位具体错误

执行以下命令让Node在出现未处理Promise拒绝时直接终止并输出详细错误栈,帮助定位问题根源:

node --unhandled-rejections=strict node_modules/@angular/cli/bin/ng lint

4. 清理依赖缓存后重装

依赖缓存可能导致版本冲突,执行以下步骤重置依赖:

  • 删除node_modules文件夹:rm -rf node_modules(Windows环境用rd /s /q node_modules)
  • 删除package-lock.json或yarn.lock文件
  • 重新安装依赖:npm install或yarn install

内容的提问来源于stack exchange,提问作者Bogdan Pătrăucean

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 02:25:16