Summary
The angular-localize-init-warning plugin in @angular/build always warns on a direct import '@angular/localize/init', and recommends moving the import to the polyfills array. For apps using @angular-architects/native-federation in shimMode (es-module-shims), the polyfills-only path does not work — $localize is not registered inside the shim graph at runtime and the app fails with $localize is not a function. The supported workaround is to keep the direct import in main.ts, but there is currently no way to silence the resulting warning.
This request is for a per-project opt-out so federated apps can keep a clean build log.
Current behaviour
@angular/build build emits:
Direct import of '@angular/localize/init' detected. This may lead to undefined behavior.
Include '@angular/localize/init' as a polyfill instead.
- The warning fires on every dev-server rebuild.
- Moving the import to
polyfills and removing it from main.ts breaks the app at runtime in native-federation shimMode.
Why the recommended fix doesn't work for shim-based federation
- Native-federation uses es-module-shims to provide an import map at runtime.
- The polyfills bundle executes before the import map exists, so polyfill-only registration of
$localize is invisible to shimmed remote modules.
- The supported pattern (documented inline in many federation shells) is to put
import '@angular/localize/init' at the top of main.ts so it runs inside the shim graph.
Proposed fix
Add a per-project build option to suppress this specific warning, e.g.:
Or alternatively gate the warning on the absence of a known federation plugin / shim-mode flag.
Minimal repro
- Create an app via
@angular-architects/native-federation schematic with shim mode.
- Add
@angular/localize and enable localize: true in angular.json.
- Removing
import '@angular/localize/init' from main.ts (with the polyfill correctly listed) reproduces $localize is not a function at runtime; keeping it reproduces the warning.
Related
Environment
@angular/build: ^21.1.2
@angular/localize: ^21.1.0
@angular-architects/native-federation: ^21.1.0
Summary
The
angular-localize-init-warningplugin in@angular/buildalways warns on a directimport '@angular/localize/init', and recommends moving the import to thepolyfillsarray. For apps using@angular-architects/native-federationin shimMode (es-module-shims), the polyfills-only path does not work —$localizeis not registered inside the shim graph at runtime and the app fails with$localize is not a function. The supported workaround is to keep the direct import inmain.ts, but there is currently no way to silence the resulting warning.This request is for a per-project opt-out so federated apps can keep a clean build log.
Current behaviour
@angular/buildbuild emits:polyfillsand removing it frommain.tsbreaks the app at runtime in native-federation shimMode.Why the recommended fix doesn't work for shim-based federation
$localizeis invisible to shimmed remote modules.import '@angular/localize/init'at the top ofmain.tsso it runs inside the shim graph.Proposed fix
Add a per-project build option to suppress this specific warning, e.g.:
Or alternatively gate the warning on the absence of a known federation plugin / shim-mode flag.
Minimal repro
@angular-architects/native-federationschematic with shim mode.@angular/localizeand enablelocalize: trueinangular.json.import '@angular/localize/init'frommain.ts(with the polyfill correctly listed) reproduces$localize is not a functionat runtime; keeping it reproduces the warning.Related
$localize. #27786 (closed) — earlier discussion of the warning, no federation-aware pathng testin windows fails with EMFILE error #977, fix(): npm link the generated project in our e2e tests #197 (all open) — upstream gaps in native-federation i18n / polyfills handlingEnvironment
@angular/build: ^21.1.2@angular/localize: ^21.1.0@angular-architects/native-federation: ^21.1.0