Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular SSR build route resolve issue #29117

Closed
captainDuckay opened this issue Dec 12, 2024 · 1 comment
Closed

Angular SSR build route resolve issue #29117

captainDuckay opened this issue Dec 12, 2024 · 1 comment

Comments

@captainDuckay
Copy link

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

No

Description

In an Angular Server-Side Rendering (SSR) application, I observed unexpected behavior during the ng build process. Specifically:

  • The ng build step attempts to execute all the code within the route resolve functions. While this behavior might be expected in a pre-rendered page setup, it does not align with expectations for a server-side rendered application, where the resolve should execute at runtime on the server, not during the build phase.
  • This issue appears to be isolated to the route defined as path: '**'. Only this wildcard route’s resolve functions are executed during the build process, which seems incorrect and inconsistent with the behavior of other routes.

This behavior poses significant problems for applications relying on internal APIs, as it results in build failures if the APIs are inaccessible from the build environment.

Note that changing the renderMode in the server routes doesn't change any behavior in this regard.

The issue was identified while building the application in a GitHub workflow using ubuntu-latest as the runner. Our internal API, which is accessible only within the internal network, was unreachable during the build process.
Luckily it doesn't terminate the build, but it still feels like an unexpected behavior.

Steps to Reproduce:

  1. Clone the provided minimal reproduction repository.
  2. Attempt to build the application using ng build with the provided configuration.
  3. Observe that the resolve function in the route with path: '**' executes during the build step, causing it to fail if the API is unreachable.

Expected Behavior:

For a server-side rendered application:

  1. Resolve functions should execute at runtime on the server, not during the build step.
  2. The build process should only package the application for deployment, without executing runtime code such as route resolves.

Please provide a link to a minimal reproduction of the bug

https://github.com/captainDuckay/resolver-problem

Please provide the exception or error you saw

ERROR Pr {
  headers: r {
    headers: Map(0) {},
    normalizedNames: Map(0) {},
    lazyInit: undefined,
    lazyUpdate: null
  },
  status: 0,
  statusText: 'Unknown Error',
  url: 'https://blablablalbatest.test/api/testdata',
  ok: false,
  type: undefined,
  name: 'HttpErrorResponse',
  message: 'Http failure response for https://blablablalbatest.test/api/testdata: 0 undefined',
  error: TypeError: fetch failed
      at node:internal/deps/undici/undici:13392:13
      at a.invoke (file:///Users/not/WebstormProjects/repro-app/.angular/prerender-root/21ff0b3d-ccbd-48cc-a58c-56f355dc6a25/polyfills.server.mjs:3:6715)
      at l.run (file:///Users/not/WebstormProjects/repro-app/.angular/prerender-root/21ff0b3d-ccbd-48cc-a58c-56f355dc6a25/polyfills.server.mjs:3:1985)
      at file:///Users/not/WebstormProjects/repro-app/.angular/prerender-root/21ff0b3d-ccbd-48cc-a58c-56f355dc6a25/polyfills.server.mjs:4:576
      at a.invokeTask (file:///Users/not/WebstormProjects/repro-app/.angular/prerender-root/21ff0b3d-ccbd-48cc-a58c-56f355dc6a25/polyfills.server.mjs:3:7341)
      at l.runTask (file:///Users/not/WebstormProjects/repro-app/.angular/prerender-root/21ff0b3d-ccbd-48cc-a58c-56f355dc6a25/polyfills.server.mjs:3:2628)
      at R (file:///Users/not/WebstormProjects/repro-app/.angular/prerender-root/21ff0b3d-ccbd-48cc-a58c-56f355dc6a25/polyfills.server.mjs:3:9382)
      at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
    [cause]: Error: getaddrinfo ENOTFOUND blablablalbatest.test
        at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:120:26) {
      errno: -3008,
      code: 'ENOTFOUND',
      syscall: 'getaddrinfo',
      hostname: 'blablablalbatest.test'
    }
  }
}
Browser bundles      
Initial chunk files   | Names            |  Raw size | Estimated transfer size
chunk-42OR2LGY.js     | -                | 138.27 kB |                41.48 kB
main-V7QEP3S4.js      | main             | 123.27 kB |                31.88 kB
polyfills-FFHMD2TL.js | polyfills        |  34.52 kB |                11.28 kB
styles-5INURTSO.css   | styles           |   0 bytes |                 0 bytes

                      | Initial total    | 296.06 kB |                84.63 kB

Lazy chunk files      | Names            |  Raw size | Estimated transfer size
chunk-ITHPYWXR.js     | error-component  | 312 bytes |               312 bytes
chunk-YSOHETL2.js     | test-component   | 309 bytes |               309 bytes


Server bundles       
Initial chunk files   | Names            |  Raw size
server.mjs            | server           | 844.42 kB |                        
main.server.mjs       | main.server      | 633.63 kB |                        
polyfills.server.mjs  | polyfills.server | 268.60 kB |                        
chunk-6GZ6XUNF.mjs    | -                | 136.71 kB |                        
chunk-X2SEQXRR.mjs    | -                |   2.41 kB |                        
chunk-GFUZYSQG.mjs    | -                |   1.24 kB |                        

Lazy chunk files      | Names            |  Raw size
chunk-EJSJJTUO.mjs    | xhr2             |  12.14 kB |                        
chunk-TNO4MGIL.mjs    | xhr2             |  12.07 kB |                        
chunk-A4T2JHCR.mjs    | error-component  | 375 bytes |                        
chunk-EBTR7VEV.mjs    | test-component   | 372 bytes |                        

Prerendered 0 static routes.
Application bundle generation complete. [7.415 seconds]

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 19.0.4
Node: 22.11.0
Package Manager: npm 10.9.0
OS: darwin arm64

Angular: 19.0.3
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1900.4
@angular-devkit/build-angular   19.0.4
@angular-devkit/core            19.0.4
@angular-devkit/schematics      19.0.4
@angular/cli                    19.0.4
@angular/ssr                    19.0.4
@schematics/angular             19.0.4
rxjs                            7.8.1
typescript                      5.6.3
zone.js                         0.15.0

Anything else?

  • This issue might be related to the prerendering process mistakenly engaging the resolve function for the wildcard route.
  • Clarification on whether this is intended behavior for SSR or a misconfiguration in the build process would be helpful.
@alan-agius4 alan-agius4 transferred this issue from angular/angular Dec 12, 2024
@alan-agius4
Copy link
Collaborator

Duplicate of #29085.

This fix will be available in the next patch release.

@alan-agius4 alan-agius4 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants