Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error:JIT compilation failed for injectable class PlatformLocation {} while doing AngularJS to Angular 13 migration

Doing migration for application form angularjs to angular v13 right now i'm trying to dual boot the application.

and getting the following error in browser console:

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.

below are the files i have used to configure this dual boot process.

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']);
});

i'm not looking to do import '@angular/compiler'; in main.ts although that seems to work temporarily but it causing similar problems later down the line while migrating components.

Ideally i would like to not disable AOT or IVY.

Have tried

  1. "postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points"
  2. npm update
  3. babel-loader in webpack configurations.
like image 557
mandav Avatar asked May 20 '26 21:05

mandav


2 Answers

You are most likely missing importing the angular compiler. In order to solve the issue, add the following line at the top of the main.ts file:

import '@angular/compiler';

Once you have added the above, restart your server and/or build your app again and that should fix it.

like image 145
Devner Avatar answered May 22 '26 13:05

Devner


My solution was to delete the dist and .angular folder. Maybe it was a cache problem.

like image 29
user6266369 Avatar answered May 22 '26 12:05

user6266369