Skip to content

renderModuleFactory does not reject when error is thrown in application #33642

Open

Description

@FrozenPandaz

🐞 bug report

Affected Package

@angular/platform-server

Is this a regression?

No, I tested a v4 and v6 and the behavior is consistent

Description

renderModuleFactory does not reject for errors thrown during rendering.

Examples:

  • @Component ngOnInit
  • Router resolve
  • Probably more

🔬 Minimal Reproduction

https://github.com/FrozenPandaz/angular-bugs/tree/render-module-factory

npm i && npm run prerender

🔥 Exception or Error

 jason@pop-os  ~/projects/temp/temp/angular-bugs   render-module-factory  npm run prerender

> [email protected] prerender /home/jason/projects/temp/temp/angular-bugs
> ng build && ng run ng8-app:server && node ./main.js

Generating ES5 bundles for differential loading...
ES5 bundle generation complete.

chunk {runtime} runtime-es2015.js, runtime-es2015.js.map (runtime) 6.16 kB [entry] [rendered]
chunk {runtime} runtime-es5.js, runtime-es5.js.map (runtime) 6.16 kB [entry] [rendered]
chunk {styles} styles-es2015.js, styles-es2015.js.map (styles) 10.1 kB [initial] [rendered]
chunk {styles} styles-es5.js, styles-es5.js.map (styles) 14.2 kB [initial] [rendered]
chunk {main} main-es2015.js, main-es2015.js.map (main) 48.2 kB [initial] [rendered]
chunk {main} main-es5.js, main-es5.js.map (main) 55.3 kB [initial] [rendered]
chunk {polyfills-es5} polyfills-es5.js, polyfills-es5.js.map (polyfills-es5) 789 kB [initial] [rendered]
chunk {vendor} vendor-es2015.js, vendor-es2015.js.map (vendor) 3.75 MB [initial] [rendered]
chunk {vendor} vendor-es5.js, vendor-es5.js.map (vendor) 5.21 MB [initial] [rendered]
chunk {polyfills} polyfills-es2015.js, polyfills-es2015.js.map (polyfills) 264 kB [initial] [rendered]
Date: 2019-11-07T04:43:04.373Z - Hash: c69b66b49129c074781b - Time: 13236ms
Hash: 2a979d82dfc31ad8eb0a
Time: 2896ms
Built at: 11/06/2019 11:43:08 PM
      Asset      Size  Chunks             Chunk Names
    main.js    65 KiB    main  [emitted]  main
main.js.map  36.2 KiB    main  [emitted]  main
Entrypoint main = main.js main.js.map
chunk {main} main.js, main.js.map (main) 54.8 KiB [entry] [rendered]
ERROR Error: hi
    at AppComponent.ngOnInit (/home/jason/projects/temp/temp/angular-bugs/dist/ng8-app-server/main.js:233:15)
    at checkAndUpdateDirectiveInline (/home/jason/projects/temp/temp/angular-bugs/node_modules/@angular/core/bundles/core.umd.js:21240:23)
    at checkAndUpdateNodeInline (/home/jason/projects/temp/temp/angular-bugs/node_modules/@angular/core/bundles/core.umd.js:29610:24)
    at checkAndUpdateNode (/home/jason/projects/temp/temp/angular-bugs/node_modules/@angular/core/bundles/core.umd.js:29572:20)
    at prodCheckAndUpdateNode (/home/jason/projects/temp/temp/angular-bugs/node_modules/@angular/core/bundles/core.umd.js:30113:9)
    at Object.updateDirectives (/home/jason/projects/temp/temp/angular-bugs/dist/ng8-app-server/main.js:187:264)
    at Object.updateDirectives (/home/jason/projects/temp/temp/angular-bugs/node_modules/@angular/core/bundles/core.umd.js:29901:76)
    at Object.checkAndUpdateView (/home/jason/projects/temp/temp/angular-bugs/node_modules/@angular/core/bundles/core.umd.js:29554:18)
    at ViewRef_.detectChanges (/home/jason/projects/temp/temp/angular-bugs/node_modules/@angular/core/bundles/core.umd.js:20829:26)
    at ApplicationRef.tick (/home/jason/projects/temp/temp/angular-bugs/node_modules/@angular/core/bundles/core.umd.js:27224:30)
promise resolved
 jason@pop-os  ~/projects/temp/temp/angular-bugs   render-module-factory  

🌍 Your Environment

Angular Version:


 ✘ jason@pop-os  ~/projects/temp/fs-datatable   master  ng v

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 7.3.1
Node: 10.16.3
OS: linux x64
Angular: 7.2.15
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.9
@angular-devkit/build-angular     0.13.9
@angular-devkit/build-optimizer   0.13.9
@angular-devkit/build-webpack     0.13.9
@angular-devkit/core              7.3.9
@angular-devkit/schematics        7.3.1
@angular/cdk                      7.3.7
@angular/cli                      7.3.1
@angular/material                 7.3.7
@ngtools/webpack                  7.3.9
@schematics/angular               7.3.1
@schematics/update                0.13.1
rxjs                              6.3.3
typescript                        3.2.2
webpack                           4.29.0

Activity

  1. FrozenPandaz commented on Nov 7, 2019

    @FrozenPandaz
    ContributorAuthor
  2. added
    area: server
    on Nov 7, 2019
  3. added this to the needsTriage milestone on Nov 7, 2019
  4. modified the milestones: needsTriage, Backlog on Nov 19, 2019
  5. 23 remaining items

  6. webberig commented on Dec 2, 2025

    @webberig

    I ended up here while investigating an issue on our production website. A page was returning a 200 OK response in a corrupted state. I noticed that the ng-state was missing in the response.

    The server logs mentioned following error:

       Ignoring BEFORE_APP_SERIALIZED Exception:  TypeError: Converting circular structure to JSON
           --> starting at object with constructor 'r'
           |     property 'upload' -> object with constructor 'b'
           --- property '_request' closes the circle
           at JSON.stringify (<anonymous>)
           at e.toJson (file:///app/dist/apps/web/server/chunk-7FR65NHR.mjs:5:31328)
    

    Due to an application error, there was an unserializable object being put in the transferstate object. This caused the error above. Unfortunately, the error is being swallowed so the page returns a 200 OK without the transferstate object, which in turn caused some issues for our website client-side.

    The code containing the error handling is here:

    // Ignore exceptions.

    Ideally we have a way of handling this kind of error and produce an error page instead.

  7. alan-agius4 commented on Dec 2, 2025

    @alan-agius4
    Contributor

    @webberig, your issue seems something slightly different from the original issue. Do you mind opening an new issue? Thanks.

  8. zola-dev commented on Jul 7, 2026

    @zola-dev

    Our report (angular/angular-cli#33522) was closed as a duplicate of this issue. It is on the current pipeline: @angular/build prerendering with @angular/ssr on v22, where renderModuleFactory (this issue's title) no longer exists.

    The outcome is the same as described here:
    a component render error is routed to the default ErrorHandler during ApplicationRef.tick and only logged, whenStable() resolves after it, and the build exits 0 shipping the degraded page.

    We opened it as a separate issue following the suggestion in this thread (Dec 2025) to open a new one for a related report:
    #33642 (comment)
    It has a fresh v22 reproduction and a proposed mechanism (exposing rethrowApplicationErrors, which TestBed already has, for server/prerender rendering).

    Could the new report be reopened as its own tracker for the current pipeline? If this issue is meant to cover it as well, glad to keep it here.

  9. arturovt commented on Sep 29, 2026

    @arturovt
    Contributor

    @JeanMeche this can be closed. renderModuleFactory no longer exists: platform-server exports renderApplication and renderModule now, so the reported API cannot be tested.

    The behavior is also the ErrorHandler contract rather than a rendering bug. An error thrown in ngOnInit goes to the error handler, which logs it and lets rendering continue, exactly as it does in the browser. A prerender pipeline that wants to fail on those can provide its own ErrorHandler and reject from there.

    P2 since 2019 against 7.2.15, assigned to @alan-agius4 but never started, no duplicates. If it still matters for prerendering on a current version, that belongs in the CLI repo where the pipeline lives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2area: servereffort2: daysfreq2: mediumtype: bug/fix

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions