GeezerVison is showing github.com — esm: fix missed renaming in ModuleJob.runSync · nodejs/node@dbe6e63
File tree
Expand file treeCollapse file tree
Open diff view settings
fixtures/es-modules/import-require-tla-twice
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/modules/esm/module_job.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -335,7 +335,7 @@ class ModuleJob extends ModuleJobBase { |
335 | 335 | const parentFilename = urlToFilename(parent?.filename); |
336 | 336 | this.module.hasAsyncGraph ??= this.module.isGraphAsync(); |
337 | 337 |
|
338 | | - if (this.module.async && !getOptionValue('--experimental-print-required-tla')) { |
| 338 | + if (this.module.hasAsyncGraph && !getOptionValue('--experimental-print-required-tla')) { |
339 | 339 | throw new ERR_REQUIRE_ASYNC_MODULE(filename, parentFilename); |
340 | 340 | } |
341 | 341 | if (status === kInstantiated) { |
|
Collapse file
Copy file name to clipboard +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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 | +); |
Collapse file
Copy file name to clipboard +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +const { registerHooks } = require('module'); |
| 2 | +registerHooks({ |
| 3 | + load(url, context, nextLoad) { |
| 4 | + return nextLoad(url, context); |
| 5 | + } |
| 6 | +}); |
Collapse file
Copy file name to clipboard +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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 | +} |
Collapse file
Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +await Promise.resolve('1'); |