【发布时间】:2022-11-15 05:11:28
【问题描述】:
现在正在将应用程序从 angularjs 迁移到 angular v13 我正在尝试双重启动应用程序。
并在浏览器控制台中收到以下错误:
Uncaught Error: The injectable 'PlatformLocation' needs to be compiled using the JIT compiler, but '@angular/compiler' is not available.
The injectable is part of a library that has been partially compiled.
However, the Angular Linker has not processed the library such that JIT compilation is used as fallback.
Ideally, the library is processed using the Angular Linker to become fully AOT compiled.
Alternatively, the JIT compiler should be loaded by bootstrapping using '@angular/platform-browser-dynamic' or '@angular/platform-server',
or manually provide the compiler with 'import "@angular/compiler";' before bootstrapping.
下面是我用来配置这个双启动过程的文件。
main.ts
//angularjs imports
import { DoBootstrap, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { UpgradeModule } from '@angular/upgrade/static';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
@NgModule({
imports: [
BrowserModule,
UpgradeModule
]
})
export class AppModule{
// Override Angular bootstrap so it doesn't do anything
ngDoBootstrap() {}
}
// Bootstrap using the UpgradeModule
platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
console.log("Bootstrapping in Hybrid mode with Angular & AngularJS");
const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
upgrade.bootstrap(document.body, ['codecraft']);
});
我不打算在 main.ts 中执行 import '@angular/compiler';,虽然这似乎暂时有效,但它会在稍后迁移组件时导致类似的问题。
理想情况下,我不想禁用 AOT 或 IVY。
试过
- “postinstall”:“ngcc --properties es2015 浏览器模块 main --first-only --create-ivy-entry-points”
- npm 更新
- webpack 配置中的 babel-loader。
【问题讨论】:
-
您找到解决方案了吗?
标签: angular angularjs migration jit aot