diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fbb9acd2..c01fcac34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ ## Main - +- [#1180] Set module properly when tsconfig does not contain compilerOptions.module [@matthewh] ## 12.3.2 diff --git a/source/runner/runners/utils/transpiler.ts b/source/runner/runners/utils/transpiler.ts index 081031b0e..15ca593fd 100644 --- a/source/runner/runners/utils/transpiler.ts +++ b/source/runner/runners/utils/transpiler.ts @@ -149,10 +149,14 @@ const sanitizeTSConfig = (config: any, esm: boolean = false) => { // // @see https://github.com/apollographql/react-apollo/pull/1402#issuecomment-351810274 // - if (!esm && safeConfig.compilerOptions.module) { - safeConfig.compilerOptions.module = "commonjs" - } else { - safeConfig.compilerOptions.module = "es6" + if (safeConfig.compilerOptions.module) { + if (!esm) { + // .ts files should fall back to commonjs + safeConfig.compilerOptions.module = "commonjs" + } else { + // .mts files must use `import`/`export` syntax + safeConfig.compilerOptions.module = "es6" + } } return safeConfig