Skip to content
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
4 changes: 3 additions & 1 deletion lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,9 @@ class ModuleLoader {
const loadResult = this.#loadSync(url, { format, importAttributes });

// Use the synchronous commonjs translator which can deal with cycles.
const finalFormat = loadResult.format === 'commonjs' ? 'commonjs-sync' : loadResult.format;
const finalFormat =
loadResult.format === 'commonjs' ||
loadResult.format === 'commonjs-typescript' ? 'commonjs-sync' : loadResult.format;

if (finalFormat === 'wasm') {
assert.fail('WASM is currently unsupported by require(esm)');
Expand Down
10 changes: 10 additions & 0 deletions test/es-module/test-typescript-commonjs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,13 @@ test('expect failure of a .cts file requiring esm in node_modules', async () =>
match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/);
strictEqual(result.code, 1);
});

test('cts -> require mts -> import cts', async () => {
const result = await spawnPromisified(process.execPath, [
fixtures.path('typescript/cts/issue-59963/a.cts'),
]);

strictEqual(result.stderr, '');
strictEqual(result.stdout, 'Hello from c.cts\n');
strictEqual(result.code, 0);
});
11 changes: 11 additions & 0 deletions test/es-module/test-typescript-module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,14 @@ test('execute .ts file importing a module', async () => {
strictEqual(result.stdout, 'Hello, TypeScript!\n');
strictEqual(result.code, 0);
});

test('mts -> import cts -> require mts', async () => {
const result = await spawnPromisified(process.execPath, [
'--no-warnings',
fixtures.path('typescript/mts/issue-59963/a.mts'),
]);

strictEqual(result.stderr, '');
strictEqual(result.stdout, 'Hello from c.mts\n');
strictEqual(result.code, 0);
});
3 changes: 3 additions & 0 deletions test/fixtures/typescript/cts/issue-59963/a.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { message } = require("./b.mts");
interface Foo {};
console.log(message);
2 changes: 2 additions & 0 deletions test/fixtures/typescript/cts/issue-59963/b.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
interface Foo {};
export { message } from "./c.cts";
2 changes: 2 additions & 0 deletions test/fixtures/typescript/cts/issue-59963/c.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const message: string = "Hello from c.cts";
module.exports = { message };
3 changes: 3 additions & 0 deletions test/fixtures/typescript/mts/issue-59963/a.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { message } from "./b.cts";
interface Foo {};
console.log(message);
3 changes: 3 additions & 0 deletions test/fixtures/typescript/mts/issue-59963/b.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { message } = require("./c.mts");
interface Foo {};
module.exports = { message };
1 change: 1 addition & 0 deletions test/fixtures/typescript/mts/issue-59963/c.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const message: string = "Hello from c.mts";
Loading