Skip to content

Commit dbe6e63

Browse files
joyeecheungtargos
authored andcommitted
esm: fix missed renaming in ModuleJob.runSync
https://redirect.github.com/nodejs/node/pull/59675 missed a case when renaming .async to .hasAsyncGraph. This fixes that and add a test that would previously crash with the missed rename. PR-URL: #59724 Refs: #59675 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Ulises Gascón <[email protected]> Reviewed-By: Marco Ippolito <[email protected]>
1 parent dcdb259 commit dbe6e63

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

lib/internal/modules/esm/module_job.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ class ModuleJob extends ModuleJobBase {
335335
const parentFilename = urlToFilename(parent?.filename);
336336
this.module.hasAsyncGraph ??= this.module.isGraphAsync();
337337

338-
if (this.module.async && !getOptionValue('--experimental-print-required-tla')) {
338+
if (this.module.hasAsyncGraph && !getOptionValue('--experimental-print-required-tla')) {
339339
throw new ERR_REQUIRE_ASYNC_MODULE(filename, parentFilename);
340340
}
341341
if (status === kInstantiated) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
// This tests that in the require() in imported CJS can retry loading an ESM with TLA
3+
// twice and get the correct error both times.
4+
5+
require('../common');
6+
const { spawnSyncAndAssert } = require('../common/child_process');
7+
const fixtures = require('../common/fixtures');
8+
const assert = require('assert');
9+
10+
spawnSyncAndAssert(
11+
process.execPath,
12+
['--import', fixtures.fileURL('es-modules', 'import-require-tla-twice', 'hook.js'),
13+
fixtures.path('es-modules', 'import-require-tla-twice', 'require-tla.js'),
14+
],
15+
{
16+
stdout(output) {
17+
const matches = output.matchAll(/e\.code === ERR_REQUIRE_ASYNC_MODULE true/g);
18+
assert.strictEqual([...matches].length, 2);
19+
}
20+
}
21+
);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const { registerHooks } = require('module');
2+
registerHooks({
3+
load(url, context, nextLoad) {
4+
return nextLoad(url, context);
5+
}
6+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
try {
2+
require('./tla.mjs');
3+
} catch (e) {
4+
console.log('e.code === ERR_REQUIRE_ASYNC_MODULE', e.code === 'ERR_REQUIRE_ASYNC_MODULE');
5+
}
6+
7+
try {
8+
require('./tla.mjs');
9+
} catch (e) {
10+
console.log('e.code === ERR_REQUIRE_ASYNC_MODULE', e.code === 'ERR_REQUIRE_ASYNC_MODULE');
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
await Promise.resolve('1');

0 commit comments

Comments
 (0)