Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esm: throw ERR_REQUIRE_ESM instead of ERR_INTERNAL_ASSERTION #54868

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,6 @@ class ModuleLoader {
* @returns {ModuleJobBase}
*/
getModuleJobForRequire(specifier, parentURL, importAttributes) {
assert(getOptionValue('--experimental-require-module'));

const parsed = URLParse(specifier);
if (parsed != null) {
const protocol = parsed.protocol;
Expand All @@ -346,6 +344,9 @@ class ModuleLoader {
}

const { url, format } = resolveResult;
if (!getOptionValue('--experimental-require-module')) {
throw new ERR_REQUIRE_ESM(url, true);
}
const resolvedImportAttributes = resolveResult.importAttributes ?? importAttributes;
let job = this.loadCache.get(url, resolvedImportAttributes.type);
if (job !== undefined) {
Expand Down
12 changes: 12 additions & 0 deletions test/es-module/test-typescript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ test('execute a TypeScript file with imports', async () => {
strictEqual(result.code, 0);
});

test('execute a TypeScript file with imports', async () => {
const result = await spawnPromisified(process.execPath, [
'--no-warnings',
'--eval',
`assert.throws(() => require(${JSON.stringify(fixtures.path('typescript/ts/test-import-fs.ts'))}), {code: 'ERR_REQUIRE_ESM'})`,
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
]);

strictEqual(result.stderr, '');
strictEqual(result.stdout, '');
strictEqual(result.code, 0);
});

test('execute a TypeScript file with imports with default-type module', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-strip-types',
Expand Down
Loading