Skip to content

Allow opting out of "Direct import of '@angular/localize/init'" warning for federated / shim-based builds #33224

@murtazabali

Description

@murtazabali

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.:

// angular.json
{
  "projects": {
    "shell": {
      "architect": {
        "build": {
          "options": {
            "allowDirectLocalizeImport": true
          }
        }
      }
    }
  }
}

Or alternatively gate the warning on the absence of a known federation plugin / shim-mode flag.

Minimal repro

  1. Create an app via @angular-architects/native-federation schematic with shim mode.
  2. Add @angular/localize and enable localize: true in angular.json.
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions