Angular 9 introduced a global '$localize()' function that needs to be loaded
You need to make sure you have the @angular/localize package first:
npm install @angular/localize --save
Then, import '@angular/localize/init'
in your polyfills.ts file just like the error says
The best way if you are using Angular CLI is to run
ng add @angular/localize
It will take care of it automatically
Or else
import '@angular/localize/init';
to your polyfills.ts
Tested with Angular 9
This error started to appear after I upgraded a large Nx/Angular CLI application with multiple sub apps to Angular 10. The solution suggested in the error (Please run ng add @angular/localize
from the Angular CLI) does not work if the application contains multiple apps. Each of these auto-generated app had its own polyfill.ts
. I manually added the import (import '@angular/localize/init';
) in each of the polyfill.ts file. To fix same error while running unit tests, I also had to add the import in test.ts file of libs.
If you have many angular projects in same workspace, running
ng add @angular/localize
will add import statement import '@angular/localize/init'
to polyfills.ts in default Project only,i think this will be fixed in later updates.
so you need to add import '@angular/localize/init'
manually to polyfills.ts in other projects.