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

Angular 14中PlatformLocation依赖JIT编译报错求助

Angular报错:PlatformLocation需JIT编译但@angular/compiler不可用,Linker配置及JIT导入均无效

报错信息

Error: The injectable 'PlatformLocation' needs to be compiled using the JIT compiler, but '@angular/compiler' is not available.
该可注入项属于已部分编译的库,但Angular Linker未处理该库,无法回退到JIT编译。
理想方案是用Angular Linker处理库以实现全AOT编译;也可通过@angular/platform-browser-dynamic或@angular/platform-server引导加载JIT编译器,或在引导前手动导入'@angular/compiler'。

已尝试的解决方案

  • 使用babel-loader,在webpack配置中直接添加'@angular/compiler-cli/linker/babel'作为插件,导入时出现语法错误;将package.json的type改为module后,webpack配置中的require语句又报错。
  • 执行npm update,无任何效果。
  • 在app.main.ts最顶部添加import '@angular/compiler';,报错依旧。

相关环境配置

依赖包版本列表

<此处补充具体依赖版本,例如:@angular/core: 14.2.0,@angular/compiler-cli: 14.2.0等>

tsconfig.json配置

<此处补充完整tsconfig.json内容>

目前找不到其他可行方案,请求帮助解决该问题。

内容的提问来源于stack exchange,提问作者D.Zet

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 14:05:23