node/test/es-module/test-require-module-tla-retry-require.js
Joyee Cheung 8aac7da7d6
module: fix error thrown from require(esm) hitting TLA repeatedly
This tracks the asynchronicity in the ModuleWraps when they turn out to
contain TLA after instantiation, and throw the right error
(ERR_REQUIRE_ASYNC_MODULE) when it's required again. It removes
the freezing of ModuleWraps since it's not meaningful to freeze
this when the rest of the module loader is mutable, and we
can record the asynchronicity in the ModuleWrap right after
compilation after we get a V8 upgrade that contains
v8::Module::HasTopLevelAwait() instead of searching through
the module graph repeatedly which can be slow.

PR-URL: https://github.com/nodejs/node/pull/55520
Fixes: https://github.com/nodejs/node/issues/55516
Refs: https://github.com/nodejs/node/issues/52697
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
2024-10-29 21:15:19 +00:00

17 lines
455 B
JavaScript

// This tests that after failing to require an ESM that contains TLA,
// retrying with require() still throws, and produces consistent results.
'use strict';
require('../common');
const assert = require('assert');
assert.throws(() => {
require('../fixtures/es-modules/tla/resolved.mjs');
}, {
code: 'ERR_REQUIRE_ASYNC_MODULE'
});
assert.throws(() => {
require('../fixtures/es-modules/tla/resolved.mjs');
}, {
code: 'ERR_REQUIRE_ASYNC_MODULE'
});