Skip to content

zone.js/node breaks for fs.realpath.native and fs.realpathSync.native #45546

@lamweili

Description

@lamweili

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

Don't known / other

Is this a regression?

No

Description

  1. Using the ready-made https://angular.io/generated/zips/universal/universal.zip from https://angular.io/guide/universal.

  2. Edited server.ts or the TypeScript would whine (TS4111) and refuse to run.

    -  const port = process.env.PORT || 4000;
    +  const port = process.env['PORT'] || 4000;
  3. I added the following at the very beginning of the server.ts:

    +  console.log("NODEJS VERSION:", process.version);
    
    +  console.log("=====1=====");
    +  import * as fs from 'fs';
    +  console.log("2nd-level API fs.appendFile:", fs.appendFile); // a second-level API (fs.xxx)
    +  console.log("2nd-level API fs.realpath:", fs.realpath);
    +  console.log("3rd-level API fs.realpath.native:", fs.realpath.native); // a third-level API (fs.xxx.yyy)
    
    =  import 'zone.js/node';
    
    +  console.log("=====2=====");
    +  console.log("2nd-level API fs.appendFile:", fs.appendFile); // a second-level API (fs.xxx)
    +  console.log("2nd-level API fs.realpath:", fs.realpath);
    +  console.log("3rd-level API fs.realpath.native:", fs.realpath.native); // a third-level API (fs.xxx.yyy)
    
    =  import { ngExpressEngine } from '@nguniversal/express-engine';
  4. npm install followed by npm run dev:ssr command.

  5. It seems like the import 'zone.js/node'; did something to the fs.
    fs.realpath.native become undefined from the logs.

    image

  6. It does seem like zone.js/node did not factor in fs third-level functions. From the fs API documentation, most are second-level functions (i.e. fs.xxx). But there are 2 exceptions since NodeJS 9.2.0 that are in third-level (i.e. fs.xxx.yyy), which are fs.realpath.native and fs.realpathSync.native. So when the package did some wrapping around, the third-level functions broke.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

`fs.realpath.native` is `undefined`
`fs.realpathSync.native` is `undefined`

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

Angular CLI: 13.3.1
Node: 14.19.1
Package Manager: npm 6.14.16
OS: win32 x64

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

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1303.1 (cli-only)
@angular-devkit/build-angular   13.3.1
@angular-devkit/core            13.3.1 (cli-only)
@angular-devkit/schematics      13.3.1 (cli-only)
@nguniversal/builders           13.1.0
@nguniversal/express-engine     13.1.0
@schematics/angular             13.3.1 (cli-only)
rxjs                            7.4.0
typescript                      4.5.5

Anything else?

Fixed by PR #45552

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A relatively minor issue that is not relevant to core functionsarea: zonesIssues related to zone.jsstate: has PR

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions