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

Angular 9升级至16后构建失败问题求助

Angular 9 升级至16版本构建错误解决方案

错误1:TypeScript版本不兼容

Error: Failed to initialize Angular compilation - The Angular Compiler requires TypeScript >=4.9.3 and <5.2.0 but 5.2.2 was found instead.

  • 解决方案:安装Angular 16兼容的TypeScript版本(范围为>=4.9.3且<5.2.0),执行以下命令:
    npm install typescript@~5.1.6 --save-dev
    

错误2:无法解析ng-pick-datetime-ex的CSS路径

Error: Can't resolve '~ng-pick-datetime-ex/assets/style/picker.min.css' in '/ngularsrv/src'

  • 解决方案:
    1. Webpack 5已移除对~前缀引用node_modules资源的支持,修改src/styles.css中的路径:
      将~ng-pick-datetime-ex/assets/style/picker.min.css改为ng-pick-datetime-ex/assets/style/picker.min.css,或使用完整相对路径../node_modules/ng-pick-datetime-ex/assets/style/picker.min.css。
    2. 检查ng-pick-datetime-ex包是否兼容Angular 16,若不兼容需升级该包至对应兼容版本,或寻找替代组件。

错误3:Angular Webpack插件初始化失败

Error: Emit attempted before Angular Webpack plugin initialization.

  • 解决方案:
    1. 清理依赖缓存并重新安装:
      npm cache clean --force
      rm -rf node_modules package-lock.json
      npm install
      
    2. 确认@angular-devkit/build-angular与@angular/cli版本一致(当前均为16.2.0,已符合要求)。
    3. 若项目有自定义Webpack配置,需适配Webpack 5的规则(Angular 12+默认使用Webpack 5),移除或更新旧配置中与Webpack 5冲突的部分。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 02:58:23