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

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

Closed
lamweili opened this issue Apr 6, 2022 · 1 comment
Closed
Labels
area: zones Issues related to zone.js P4 A relatively minor issue that is not relevant to core functions state: has PR
Milestone

Comments

@lamweili
Copy link

lamweili commented Apr 6, 2022

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

@JoostK JoostK added the area: zones Issues related to zone.js label Apr 6, 2022
@ngbot ngbot bot added this to the needsTriage milestone Apr 6, 2022
lamweili added a commit to lamweili/angular that referenced this issue Apr 6, 2022
…ative

Closes angular#45546

It patches the nested functions of `fs.realpath.native` and `fs.realpathSync.native` first, storing in a temporary space, before patching the usual `fs` functions (which will cause the nested functions to be `undefined`). Lastly, it populates back the patched nested functions from the temporary space back to `fs`.
lamweili added a commit to lamweili/angular that referenced this issue Apr 6, 2022
Closes angular#45546

It patches the nested functions `fs.realpath.native` and `fs.realpathSync.native` first, storing them in a temporary space, before patching the usual `fs` functions (which will cause the nested functions to be `undefined`). Lastly, it populates back the patched nested functions from the temporary space back to `fs`.
lamweili added a commit to lamweili/angular that referenced this issue Apr 6, 2022
Closes angular#45546

It patches the nested functions `fs.realpath.native` and `fs.realpathSync.native` first, storing them in a temporary space, before patching the usual `fs` functions (which will cause the nested functions to be `undefined`). Lastly, it populates back the patched nested functions from the temporary space back to `fs`.
lamweili added a commit to lamweili/angular that referenced this issue Apr 6, 2022
Closes angular#45546

It patches the nested functions `fs.realpath.native` and `fs.realpathSync.native` first, storing them in a temporary space, before patching the usual `fs` functions (which will cause the nested functions to be `undefined`). Lastly, it populates back the patched nested functions from the temporary space back to `fs`.
lamweili added a commit to lamweili/angular that referenced this issue Apr 6, 2022
Closes angular#45546

It patches the nested functions `fs.realpath.native` and `fs.realpathSync.native` first, storing them in a temporary space, before patching the usual `fs` functions (which will cause the nested functions to be `undefined`). Lastly, it populates back the patched nested functions from the temporary space back to `fs`.
lamweili added a commit to lamweili/angular that referenced this issue Apr 6, 2022
Closes angular#45546

It patches the nested functions `fs.realpath.native` and `fs.realpathSync.native` first, storing them in a temporary space, before patching the usual `fs` functions (which will cause the nested functions to be `undefined`). Lastly, it populates back the patched nested functions from the temporary space back to `fs`.
@jessicajaniuk jessicajaniuk added state: has PR P4 A relatively minor issue that is not relevant to core functions labels May 19, 2022
@ngbot ngbot bot modified the milestones: needsTriage, Backlog May 19, 2022
arturovt added a commit to arturovt/angular that referenced this issue Feb 2, 2024
This commit updates the implementation of the zone.js `fs` patch to
restore the implementation of `realpath.native` and patches it as a macrotask,
along with other functions of the `fs` package. This is the only nested function
that must be patched.

Closes: angular#45546
arturovt added a commit to arturovt/angular that referenced this issue Feb 2, 2024
This commit updates the implementation of the zone.js `fs` patch to
restore the implementation of `realpath.native` and patches it as a macrotask,
along with other functions of the `fs` package. This is the only nested function
that must be patched.

Closes: angular#45546
jessicajaniuk pushed a commit that referenced this issue Feb 6, 2024
This commit updates the implementation of the zone.js `fs` patch to
restore the implementation of `realpath.native` and patches it as a macrotask,
along with other functions of the `fs` package. This is the only nested function
that must be patched.

Closes: #45546

PR Close #54208
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: zones Issues related to zone.js P4 A relatively minor issue that is not relevant to core functions state: has PR
Projects
None yet
3 participants