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

Angular 11升级后执行npm start遇TS1131等@angular/core类型错误

Angular 10迁移至11后启动报错的解决办法

问题描述

将Angular应用从10版本迁移至11版本后,因使用Node 18(不兼容Angular 11)做了调整,执行npm start时出现一系列来自@angular/core@11.2.14的TypeScript语法错误,核心错误示例如下:

Error: ../workspace-bi/node_modules/@angular/core/index.d.ts:1426:5 - error TS1131: Property or signature expected.

get selector(): string;

../workspace-bi/node_modules/@angular/core/index.d.ts:1426:9 - error TS1005: ';' expected.

get selector(): string;
         ~~~~~~~~

解决步骤

  • 降级Node版本到兼容范围:Angular 11仅支持Node 12.x或14.x(LTS版本),Node 18超出兼容区间。推荐用nvm切换版本:
    nvm install 14
    nvm use 14
    
  • 匹配对应TypeScript版本:Angular 11要求TypeScript版本为~4.0.0,高版本TS无法正确解析Angular 11的类型定义。修改package.json中的typescript版本后重新安装依赖:
    "typescript": "~4.0.0"
    
    执行清理与安装命令:
    rm -rf node_modules package-lock.json
    npm install
    
  • 修复损坏的@angular/core依赖:若类型文件因安装异常损坏,直接重新安装指定版本:
    npm install @angular/core@11.2.14 --save
    
  • 检查tsconfig.json配置:确保compilerOptions中的target设置为ES2015或更低,module设置为ESNext或CommonJS,避免高版本语法触发解析错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 02:43:10