You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sourceLocale not used for LOCALE_ID in angular 19 #59422
Well I have some places with import "@angular/localize/init";which is different from what the author describes. But without these imports I get compile errors with TS2304: Cannot find name '$localize'.
I guess the many changes to $localize probably without any migration needs some refactoring. It's very strange behaviour.
The documentation stating
It adds types: ["@angular/localize"] in the TypeScript configuration files as well as the reference to the type definition of @angular/localize at the top of the main.ts file.
Is not really helpful for migration. Localize was added before this was part of the generator. So it would really be helpful to have the actual outcome documented and not only what the generator should do which it didn't do in the past.
import "@angular/localize/init"; should never be imported directly in the code as this can cause undefined behaviour. In that case you are getting TS2304: Cannot find name '$localize'. you need to add "@angular/localize" in the types array of your tsconfig.json.
Which was changed between Angular 14 and Angular 15?
Well actually /// <reference types="@angular/localize" /> was missing in the main.ts to make it work. Had to create a new angular application and check this.
Probably this message I get in my jest unit tests now is outdated as it tells to add import "@angular/localize/init";?
It looks like your application or one of its dependencies is using i18n.
Angular 9 introduced a global `$localize()` function that needs to be loaded.
Please run `ng add @angular/localize` from the Angular CLI.
(For non-CLI projects, add `import '@angular/localize/init';` to your `polyfills.ts` file.
For server-side rendering applications add the import to your `main.server.ts` file.)
If you're not using the Angular CLI, you may need to add import "@angular/localize/init"; to your polyfills to resolve the error in this case or in your the testing setup.
However, there is an ongoing issue regarding completely removing the exports, which can be tracked here: #48545.
Nx generates tsconfig.lib.json and tsconfig.spec.json files without "@angular/localize" inside, so I replaced in tsconfig.spec.json:
"types": ["jest", "node"]
with
"types": ["jest", "node", "@angular/localize"]
and in tsconfig.lib.json:
"types": []
with
"types": ["@angular/localize"]
then removed import '@angular/localize/init'; and import { $localize } from '@angular/localize/init'; from everywhere, and everything works fine. And no more warnings :)
Activity
wartab commentedon Jan 8, 2025
Seems like it's similar to this (there's a solution in there that worked for the bug reporter):
#59405
I'm not sure if this needs to be fixed by Angular, though.
DaSchTour commentedon Jan 8, 2025
Well I have some places with
import "@angular/localize/init";which is different from what the author describes. But without these imports I get compile errors withTS2304: Cannot find name '$localize'.I guess the many changes to
$localizeprobably without any migration needs some refactoring. It's very strange behaviour.The documentation stating
Is not really helpful for migration. Localize was added before this was part of the generator. So it would really be helpful to have the actual outcome documented and not only what the generator should do which it didn't do in the past.
alan-agius4 commentedon Jan 8, 2025
import "@angular/localize/init";should never be imported directly in the code as this can cause undefined behaviour. In that case you are gettingTS2304: Cannot find name '$localize'.you need to add"@angular/localize"in thetypesarray of yourtsconfig.json.DaSchTour commentedon Jan 8, 2025
Which was changed between Angular 14 and Angular 15?
Well actually
/// <reference types="@angular/localize" />was missing in themain.tsto make it work. Had to create a new angular application and check this.wartab commentedon Jan 8, 2025
@alan-agius4 I'm not sure if there's a way for you guys to detect the wrong import in dev-mode and print a warning in the console for that?
DaSchTour commentedon Jan 8, 2025
Probably this message I get in my jest unit tests now is outdated as it tells to add
import "@angular/localize/init";?alan-agius4 commentedon Jan 8, 2025
If you're not using the Angular CLI, you may need to add
import "@angular/localize/init";to your polyfills to resolve the error in this case or in your the testing setup.However, there is an ongoing issue regarding completely removing the exports, which can be tracked here: #48545.
alan-agius4 commentedon Jan 8, 2025
We could do that, although #48545 does seem like the preferred solution
fix(@angular/build): warn when `@angular/localize/init` is imported d…
fix(@angular/build): warn when `@angular/localize/init` is imported d…
fix(@angular/build): warn when `@angular/localize/init` is imported d…
fix(@angular/build): warn when `@angular/localize/init` is imported d…
fix(@angular/build): warn when `@angular/localize/init` is imported d…
e-oz commentedon Jan 10, 2025
So if the export is completely removed, what will be the options for those who use Nx (for example)?
alan-agius4 commentedon Jan 10, 2025
With NX it's no different from using the Angular CLI, it needs to be added as a polyfill.
e-oz commentedon Jan 10, 2025
And you are correct!
Nx generates
tsconfig.lib.jsonandtsconfig.spec.jsonfiles without"@angular/localize"inside, so I replaced intsconfig.spec.json:with
and in
tsconfig.lib.json:with
then removed
import '@angular/localize/init';andimport { $localize } from '@angular/localize/init';from everywhere, and everything works fine. And no more warnings :)Thank you, @alan-agius4 !
angular-automatic-lock-bot commentedon Feb 10, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.