From 5347c4997a14fca60fca24a6a6f4d35c19184a9c Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 18 Aug 2025 16:06:02 +0200 Subject: [PATCH] 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 Reviewed-By: Filip Skokan Reviewed-By: Chengzhong Wu --- lib/internal/modules/esm/loader.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 5d90b5f4c8c..03317d13916 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -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) {