Sitelet https://github.com/angular/angular/issues/47872
Skip to content

[zone.js] Node > 16.17.1: Method Promise.prototype.then called on incompatible receiver #47872

Description

@fmalcher

Prerendering throws an error when used with a Node version > 16.17.1

🐞 Bug report

What modules are related to this issue?

  • builders
  • common
  • express-engine

Is this a regression?

Yes, the previous version in which this bug was not present was: 14.x

🔬 Minimal Reproduction

Create a new v15 CLI workspace, add SSR and run prerendering:

npx -p @angular/cli@next ng new testproject --routing --style=css
cd testproject
npm run ng -- add @nguniversal/express-engine@next
npm run ng -- run testproject:prerender

🔥 Exception or Error

Warning directly after the start:

TypeScript compiler options "target" and "useDefineForClassFields" are set to "ES2022" and "false" respectively by the Angular CLI. To control ECMA version and features use the Browerslist configuration. For more information, see https://github.com/browserslist/browserslist

Error at prerendering:

✖ Prerendering routes to testproject/browser failed.
Method Promise.prototype.then called on incompatible receiver [object Object]

This happens with Node v16.18.0 🔥 and v18.11.0 🔥. The error does not appear with Node v16.17.0 ✅ .

🌍 Your Environment


Angular CLI: 15.0.0-rc.0
Node: 18.11.0
Package Manager: npm 8.15.1
OS: darwin arm64

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

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1500.0-rc.0
@angular-devkit/build-angular   15.0.0-rc.0
@angular-devkit/core            15.0.0-rc.0
@angular-devkit/schematics      15.0.0-rc.0
@nguniversal/builders           15.0.0-next.0
@nguniversal/express-engine     15.0.0-next.0
@schematics/angular             15.0.0-rc.0
rxjs                            7.5.7
typescript                      4.8.4

Activity

  1. ohois commented on Oct 26, 2022

    @ohois

    Same problem with Angular 14.2.X and any node version > 16.17.1 (just tested it against current LTS node Version 18.12.0)

  2. changed the title [-]Prerendering error: Method Promise.prototype.then called on incompatible receiver[/-] [+]Prerendering error with Node > 16.17.1: Method Promise.prototype.then called on incompatible receiver[/+] on Oct 26, 2022
  3. fmalcher commented on Oct 26, 2022

    @fmalcher
    ContributorAuthor

    @ohois Thanks for the background info, I can confirm this!

  4. alan-agius4 commented on Oct 26, 2022

    @alan-agius4
    Contributor

    From the looks of it, it looks like a zone.js issue. Transferring to the framework repo.

  5. added this to the needsTriage milestone on Oct 26, 2022
  6. alan-agius4 commented on Oct 26, 2022

    @alan-agius4
    Contributor

    This can be replicated without universal by using the below code.

    index.js

    async function loadEsmModule(modulePath) {
      return new Function('modulePath', `return import(modulePath);`)(modulePath);
    }
    
    (async ()=> {
      require('zone.js/node');
      await loadEsmModule('@angular/core');
    })();
    $ node index.js 
    
    node:internal/per_context/primordials:440
            new SafePromise((a, b) => PromisePrototypeThen(mapFn == null ? promise : mapFn(promise, i), a, b))
                                      ^
    
    TypeError: Method Promise.prototype.then called on incompatible receiver [object Object]
        at ZoneAwarePromise.then (<anonymous>)
        at node:internal/per_context/primordials:440:35
        at new Promise (<anonymous>)
    
  7. alan-agius4 commented on Oct 26, 2022

    @alan-agius4
    Contributor

    This seems to be caused by nodejs/node#43728.

    Following a suggestion by @JiaLiPassion I have added a temporary workaround in universal via angular/universal#2879.

  8. ohois commented on Oct 26, 2022

    @ohois

    I can confirm that this workaround fixes this issue on my end.

  9. pankaj-yadav0507 commented on Oct 31, 2022

    @pankaj-yadav0507

    I can confirm that this workaround fixes this issue on my end.

    Noob question.

    Facing the same issue. But don't know how to use that temporary workaround mentioned by @alan-agius4

  10. ohois commented on Oct 31, 2022

    @ohois
  11. cipchk commented on Nov 1, 2022

    @cipchk
  12. alan-agius4 commented on Nov 1, 2022

    @alan-agius4
  13. 8 remaining items

  14. added
    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
    on Nov 16, 2022
  15. modified the milestones: needsTriage, Backlog on Nov 16, 2022
  16. changed the title [-]Prerendering error with Node > 16.17.1: Method Promise.prototype.then called on incompatible receiver[/-] [+][zone.js] Node > 16.17.1: Method Promise.prototype.then called on incompatible receiver[/+] on Dec 5, 2022
  17. angular-automatic-lock-bot commented on Mar 30, 2023

    @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.

  18. locked and limited conversation to collaborators on Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: zonesIssues related to zone.js

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions