esm: show race error message for inner module job race

The race can not only happen when the ESM is loaded by
the CommonJS loader, but can also happen to inner
module jobs in the dependency graph.

PR-URL: https://github.com/nodejs/node/pull/59519
Fixes: https://github.com/nodejs/node/issues/59366
Refs: https://github.com/abejfehr/node-22.18-issue-repro
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
Joyee Cheung authored and Michaël Zasso committed 2025-08-21 19:01:13 +02:00
1 parent 14741539a7
commit 5347c4997a
1 file changed
+4
+4
View File
@@ -471,6 +471,10 @@ class ModuleLoader {
const resolvedImportAttributes = resolveResult.importAttributes ?? importAttributes;
let job = this.loadCache.get(url, resolvedImportAttributes.type);
if (job !== undefined) {
// TODO(node:55782): this race may stop happening when the ESM resolution and loading become synchronous.
if (!job.module) {
assert.fail(getRaceMessage(url, parentURL));
}
// This module is being evaluated, which means it's imported in a previous link
// in a cycle.
if (job.module.getStatus() === kEvaluating) {