Skip to content

Commit b43c648

Browse files
committedDec 20, 2024·
fix(@angular/build): mitigate JS transformer worker execArgv errors
Node.js workers will currently fail to initialize if the `execArgv` option is used and it contains v8 specific options. This is currently problematic for the JS transformer worker because it contains a workaround to remove the SSR `--import` argument that is used to add a loader hook for SSR purposes. The filtering of the argument and subsequent use of the `execArgv` array had the potential to pass custom Node.js options to the worker and cause it to fail. These options can be passed by developers on the command line when invoking the Angular CLI. To mitigate this problem, the `execArgv` option is now only filtered and used if the SSR import argument is present in the array. Otherwise, no value is passed which allows the default Node.js behavior to be used. While this does not fully solve the problem for all projects, it does remove the problem from non-SSR projects. (cherry picked from commit 5cc62d4)
1 parent 78d84ea commit b43c648

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed
 

‎packages/angular/build/src/tools/esbuild/javascript-transformer.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import { createHash } from 'node:crypto';
1010
import { readFile } from 'node:fs/promises';
1111
import { IMPORT_EXEC_ARGV } from '../../utils/server-rendering/esm-in-memory-loader/utils';
12-
import { WorkerPool } from '../../utils/worker-pool';
12+
import { WorkerPool, WorkerPoolOptions } from '../../utils/worker-pool';
1313
import { Cache } from './cache';
1414

1515
/**
@@ -56,12 +56,18 @@ export class JavaScriptTransformer {
5656
}
5757

5858
#ensureWorkerPool(): WorkerPool {
59-
this.#workerPool ??= new WorkerPool({
59+
const workerPoolOptions: WorkerPoolOptions = {
6060
filename: require.resolve('./javascript-transformer-worker'),
6161
maxThreads: this.maxThreads,
62-
// Prevent passing `--import` (loader-hooks) from parent to child worker.
63-
execArgv: process.execArgv.filter((v) => v !== IMPORT_EXEC_ARGV),
64-
});
62+
};
63+
64+
// Prevent passing SSR `--import` (loader-hooks) from parent to child worker.
65+
const filteredExecArgv = process.execArgv.filter((v) => v !== IMPORT_EXEC_ARGV);
66+
if (process.execArgv.length !== filteredExecArgv.length) {
67+
workerPoolOptions.execArgv = filteredExecArgv;
68+
}
69+
70+
this.#workerPool ??= new WorkerPool(workerPoolOptions);
6571

6672
return this.#workerPool;
6773
}

0 commit comments

Comments
 (0)
Please sign in to comment.