Skip to content

Angular sourceLocale not compatible with SSR and Native Federation #977

@M4R1KU

Description

@M4R1KU

With what library do you have an issue?

native-federation

Reproduction of the bug/regression with instructions

https://github.com/M4R1KU/nf-ssr-locales
(Changes in this commit: M4R1KU/nf-ssr-locales@84dd0e5)

ng build shell
ng build mfe1

npm run serve:ssr:shell
npm run serve:ssr:mfe1

Open http://localhost:4200


Opening the console shows the following error:

Uncaught TypeError: The specifier “@angular/common/locales/global/de-CH” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “../” or “/”.

The locales are imported through the polyfills and the corresponding import is automatically added by the angular build process when the projects.<project-name>.i18n.sourceLocale property is set in angular.json

Through debugging the options passed to the angular builder and then subsequently esbuild, I am pretty sure that this is the problematic line.

When the externalDependencies property is set on the build options (i.e. "ssr": true in angular.json), I observe in the angular-locale-data plugin that the import to @angular/common/locales/global/* is considered to be external (here).
If ssr is set to false in the options of the @angular-architects/native-federation:build builder, this is not the case and the locale data is bundled into the polyfills.js output.

Expected behavior

I would expect the polyfills output file to always include the bundled locale data if it is set through the sourceLocale property in angular.json.

Versions of Native/Module Federation, Angular, Node, Browser, and operating system

Native Federation: 20.1.7
Angular: 20.3.7
Node: 22.19.0
Browser: Firefox 143.0.4
Operating System: Linux 6.17.1-arch1-1

Other information

Start of polyfills when ssr: true (contains plain import)

import"@angular/common/locales/global/de-CH";var ot=globalThis;function Je(o){return(ot.__Zone_symbol_prefix||"__zone_symbol__")+o}function os(){let o= ........

Start of polyfills when ssr: false (contains bundled locales)

(function(s){s.ng??={},s.ng.common??={},s.ng.common.locales??={};let o=void 0;function y(a){let p=a,S=Math.floor(Math.abs(a)),I=a.toString().replace(/^[^.]*\.?/,"").length;return S===1&&I===0?1:5}s.ng.common.locales["de-ch"]=["de-CH",[["AM","PM"]],o,[["S","M", ........

I would be willing to submit a PR to fix this issue

  • Yes
  • No

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions