Skip to content

build: unhandled exception error during prerender #29884

Description

@imaksp

Command

build

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

if route fails to prerender due to invalid http url during prerender, it gives following error, so we cannot find route having the error.

An unhandled exception occurred: Cannot read properties of undefined (reading 'stack')

Minimal Reproduction

add route with RenderMode.Prerender in new app, & call api with invalid http url in that component.
(not adding app as bug is clear in existing code, see anything else section)

Exception or Error

An unhandled exception occurred: Cannot read properties of undefined (reading 'stack')
    at /Users/***/node_modules/@angular-devkit/build-angular/node_modules/@angular/build/src/utils/server-rendering/prerender.js:153:94

Your Environment

Angular CLI: 19.2.3
Node: 22.13.1
Package Manager: yarn 4.7.0
OS: darwin arm64

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

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1902.3
@angular-devkit/build-angular   19.2.3
@angular-devkit/core            19.2.3
@angular-devkit/schematics      19.2.3
@angular/cli                    19.2.3
@angular/ssr                    19.2.3
@schematics/angular             19.2.3
rxjs                            7.8.2
typescript                      5.8.2
zone.js                         0.15.0

Anything else relevant?

See following code:

.catch((err) => {
errors.push(
`An error occurred while prerendering route '${route}'.\n\n${err.stack ?? err.message ?? err.code ?? err}`,
);

in this code if err obj is undefined it won't log exact error, & error is actually undefined in this case.

Activity

  1. imaksp commented on Mar 19, 2025

    @imaksp
    ContributorAuthor

    additional info: API url was starting with undefined instead of https://, due to one code error, it works correctly if api server fails to respond or returns an incorrect response

  2. alan-agius4 commented on Mar 19, 2025

    @alan-agius4
    Collaborator

    Are you using withFetch?

  3. imaksp commented on Mar 19, 2025

    @imaksp
    ContributorAuthor

    yes this is the related code, it also uses tanstack query:

      countriesQuery = injectQuery(() => ({
        queryKey: ['countryList'],
        queryFn: () => {
          return lastValueFrom(this.#profileService.getCountryList());
        },
      }));
  4. added theissue type on Mar 19, 2025
  5. self-assigned this
    on Mar 20, 2025
  6. added 4 commits that reference this issue on Mar 20, 2025
    c3daee5
    bb24fa4
    edba976
    21f5c77
  7. added a commit that references this issue on Mar 20, 2025
    20455e2
  8. added a commit that references this issue on Mar 20, 2025
    156a14e
  9. angular-automatic-lock-bot commented on Apr 20, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  10. locked and limited conversation to collaborators on Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions