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

Passing in V8 flags to a node process that executes ng build/serve throws #28901

Open
1 task done
jackofdiamond5 opened this issue Nov 20, 2024 · 4 comments
Open
1 task done
Assignees
Labels
area: @angular/build freq1: low Only reported by a handful of users who observe it rarely severity5: regression type: bug/fix

Comments

@jackofdiamond5
Copy link

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

18.2.12

Description

I am firing a nodejs process that executes the ng build schematic.
For example, it looks something like this - node --max-old-space-size=4096 node_modules/@angular/cli/bin/ng build. This throws because of the --max-old-space-size V8 flag that I pass in to node.

I traced the problem to this PR#28758 which uses process.execArgv and passes them in as execArgv to the options of the newly-created worker. Later on piscina will spawn a worker with the provided options, without doing any filtering, but I figured this is the intended behavior on their part.

According to nodejs when spawning worker threads, we cannot pass in any V8 flags (ref). Also, there's an open issue nodejs/node#41103 to make worker threads stop throwing errors for unsupported options but until that is resolved my best guess is that if process.execArgv is to be used, then some sort of filtering should be applied on these options before passing them in to the worker's constructor.

Minimal Reproduction

1, Create a new application with @angular/cli@19.
2. Navigate to the newly-created project's root.
3. Run node --max-old-space-size=4096 node_modules/@angular/cli/bin/ng build

Exception or Error

✘ [ERROR] Initiated Worker with invalid execArgv flags: --max-old-space-size=4096 [plugin angular-compiler]
 node_modules/piscina/dist/index.js:130:23:
      130 │         const worker = new node_worker_threads_1.Worker((0, node_...

Your Environment

Angular CLI: 19.0.0
Node: 20.17.0
Package Manager: npm 10.8.2
OS: win32 x64

Angular:
...

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1900.0 (cli-only)
@angular-devkit/core         19.0.0 (cli-only)
@angular-devkit/schematics   19.0.0 (cli-only)
@schematics/angular          19.0.0 (cli-only)

Anything else relevant?

No response

@alan-agius4 alan-agius4 added type: bug/fix freq1: low Only reported by a handful of users who observe it rarely severity5: regression area: @angular/build labels Nov 20, 2024
@clydin
Copy link
Member

clydin commented Nov 20, 2024

Thank you for the report. This is something the team will be investigating.

For max-old-space-size specifically, you may not need to use that option anymore with the Angular CLI. Newer Node.js versions have improved their memory initialization process significantly over previous versions.

@jackofdiamond5
Copy link
Author

jackofdiamond5 commented Nov 20, 2024

For max-old-space-size specifically, you may not need to use that option anymore with the Angular CLI. Newer Node.js versions have improved their memory initialization process significantly over previous versions.

@clydin Yeah you're right, I don't need the max-old-space-size anymore, I used it as a mere example to illustrate a V8 option that would cause an error when used like that.

One exception is with ng lint where we have a huge application and currently, in order to lint it, we use that flag, otherwise it runs out of memory. But without going through the code I'm going to guess that the ng lint does not spawn any workers and that's why it doesn't throw like ng serve/build do.

@viceice
Copy link

viceice commented Dec 6, 2024

I've this problem with --use-openssl-ca

@alan-agius4 alan-agius4 self-assigned this Dec 12, 2024
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Dec 12, 2024
This commit removes the use of a worker for Babel transformation of external dependencies within the ESM loader hook.

Closes angular#28901
@adzhiljano
Copy link

For max-old-space-size specifically, you may not need to use that option anymore with the Angular CLI. Newer Node.js versions have improved their memory initialization process significantly over previous versions.

Unfortunately, max-old-space-size is our only option right now. On a fairly large app, we're currently getting the following (without passing any flags):

X [ERROR] Angular compilation initialization failed. [plugin angular-compiler]

  Error [ERR_WORKER_OUT_OF_MEMORY]: Worker terminated due to reaching memory limit: JS heap out of memory
      at [kOnExit] (node:internal/worker:313:26)
      at Worker.<computed>.onexit (node:internal/worker:229:20)

We've also seen the following, that seems to happen randomly:

X [ERROR] The expression evaluated to a falsy value:

  (0, node_assert_1.default)(compilation)
 [plugin angular-compiler]

  This error came from the "onStart" callback registered here:

    node_modules/@angular/build/src/tools/esbuild/angular/compiler-plugin.js:107:18:
      107 │             build.onStart(async () => {
          ╵                   ~~~~~~~

    at setup (...\node_modules\@angular\build\src\tools\esbuild\angular\compiler-plugin.js:107:19)
    at async handlePlugins (...\node_modules\esbuild\lib\main.js:1194:20) 

Saw that PR #29118 by @alan-agius4 is Closed, can you please give us an update?
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: @angular/build freq1: low Only reported by a handful of users who observe it rarely severity5: regression type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants