angular: Localized bundle generation failed: Unexpected messageParts for `$localize` (expected an array of strings).
🐞 bug report
Affected Package
@angular/*
The issue is caused by package @angular/localizedIs this a regression?
No, we didn't have this fetaure in angular 89: ....Description
When I run ng build --configuration=production --localize I get this error:
Localized bundle generation failed: Unexpected messageParts for
$localize(expected an array of strings).
🔬 Minimal Reproduction
https://stackblitz.com/edit/angular-issue-repro2-r8en56.🔥 Exception or Error
`Localized bundle generation failed: Unexpected messageParts for `$localize` (expected an array of strings).
`
🌍 Your Environment
Angular Version:
Angular 9
Anything else relevant?
If I set optimizer to false in configuration production everything works perfectly
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 7
- Comments: 23 (9 by maintainers)
Commits related to this issue
- fix(localize): support minified ES5 `$localize` calls Some minification tooling modifies `$localize` calls to contain a comma sequence of items, where the cooked and raw values are assigned to variab... — committed to petebacondarwin/angular by petebacondarwin 4 years ago
- fix(localize): support minified ES5 `$localize` calls Some minification tooling modifies `$localize` calls to contain a comma sequence of items, where the cooked and raw values are assigned to variab... — committed to petebacondarwin/angular by petebacondarwin 4 years ago
- fix(localize): support minified ES5 `$localize` calls (#35562) Some minification tooling modifies `$localize` calls to contain a comma sequence of items, where the cooked and raw values are assigned ... — committed to angular/angular by petebacondarwin 4 years ago
I’ve applied your fix and it works for our case, everything is compiled properly now, thanks again
So this can be written (slightly more readably) as:
which is obviously TypeScript/terser/build-optimizer’s latest incantation of how to transform:
into ES5 code.
We have a test for a slightly similar arrangement in our codebase already:
But this has another level of complication… I’ll put together a PR.
It sounds to me that one of the more aggressive terser optimisations is modifying the
$localize
calls in a way that the@angular/localize
tooling cannot understand. Is it possible to build the app without localization and then find where there are instances of$localize
in the built JS files?Can you provide a reproduction of the problem? Ideally a runnable project or at least steps in how to produce one. It is difficult to debug without this