Skip to content

"Identifier 'ngServerMode' has already been declared" when prerender is true #795

@hal1984

Description

@hal1984

With what library do you have an issue?

native-federation

Reproduction of the bug/regression with instructions

https://github.com/hal1984/native-federation-19/tree/ngServerMode

  1. Clone repo
  2. npm install
  3. npm run build:mfe1 or npm run build:shell

The build crash with the following output:

npm run build:mfe1

> [email protected] build:mfe1
> ng build mfe1

 INFO  Building federation artefacts
Browser bundles      
Initial chunk files   | Names            |  Raw size | Estimated transfer size
polyfills-7JMRL5KN.js | polyfills        |  72.02 kB |                23.27 kB
main-ECDM4YT5.js      | main             |   2.50 kB |                 1.01 kB
chunk-2VMXMS7J.js     | -                | 661 bytes |               661 bytes
styles-5INURTSO.css   | styles           |   0 bytes |                 0 bytes

                      | Initial total    |  75.18 kB |                24.95 kB

Lazy chunk files      | Names            |  Raw size | Estimated transfer size
chunk-ETZQPVKB.js     | bootstrap        | 955 bytes |               955 bytes


Server bundles       
Initial chunk files   | Names            |  Raw size
polyfills.server.mjs  | polyfills.server |  31.05 kB |                        
server.mjs            | server           |  16.20 kB |                        
chunk-2XAXBCZJ.mjs    | -                |   1.44 kB |                        
chunk-3QHYWY55.mjs    | -                |   1.31 kB |                        
main.server.mjs       | main.server      | 603 bytes |                        

Lazy chunk files      | Names            |  Raw size
chunk-MWNT6HXB.mjs    | bootstrap-server | 877.14 kB |                        

Prerendered 0 static routes.
Application bundle generation failed. [1.731 seconds]

✘ [ERROR] An error occurred while extracting routes.

SyntaxError: Identifier 'ngServerMode' has already been declared
    at compileSourceTextModule (node:internal/modules/esm/utils:338:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:102:18)
    at #translate (node:internal/modules/esm/loader:468:12)
    at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:515:27)


An unhandled exception occurred: server is not started
See "/private/var/folders/67/hnw5gdhs6_x2j21kn2h8kll40000gn/T/ng-0ZBphv/angular-errors.log" for further details.
npm run build:shell 

> [email protected] build:shell
> ng build shell

 INFO  Building federation artefacts
Browser bundles      
Initial chunk files   | Names            |  Raw size | Estimated transfer size
polyfills-7JMRL5KN.js | polyfills        |  72.02 kB |                23.27 kB
chunk-OBBLAJGF.js     | -                |   4.31 kB |                 1.58 kB
main-FMDHO5MO.js      | main             | 164 bytes |               164 bytes
styles-5INURTSO.css   | styles           |   0 bytes |                 0 bytes

                      | Initial total    |  76.49 kB |                25.02 kB

Lazy chunk files      | Names            |  Raw size | Estimated transfer size
chunk-FTDKJ2JJ.js     | bootstrap        |   1.40 kB |               546 bytes


Server bundles       
Initial chunk files   | Names            |  Raw size
polyfills.server.mjs  | polyfills.server |  31.05 kB |                        
server.mjs            | server           |  14.40 kB |                        
chunk-YV667WEZ.mjs    | -                |   4.82 kB |                        
chunk-TSZOCMSY.mjs    | -                |   1.83 kB |                        
main.server.mjs       | main.server      | 603 bytes |                        

Lazy chunk files      | Names            |  Raw size
chunk-XSQPPJAP.mjs    | bootstrap-server | 877.14 kB |                        

Prerendered 0 static routes.
Application bundle generation failed. [1.820 seconds]

✘ [ERROR] An error occurred while extracting routes.

SyntaxError: Identifier 'ngServerMode' has already been declared
    at compileSourceTextModule (node:internal/modules/esm/utils:338:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:102:18)
    at #translate (node:internal/modules/esm/loader:468:12)
    at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:515:27)


An unhandled exception occurred: server is not started
See "/private/var/folders/67/hnw5gdhs6_x2j21kn2h8kll40000gn/T/ng-o223tB/angular-errors.log" for further details.

Expected behavior

Build succeeds

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

Native Federation: 19.0.16
Angular: 19.2.2
Node: 22.14.0
Browser: Chrome
Operating systems: macOS Sequoia

Other information

For MFE1 the new Server Routing have been used.
https://angular.dev/guide/hybrid-rendering.

For shell the default SSR with "prerender": "true" have been used. Both appear to fail with the same error.

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

  • Yes
  • No

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions