From c175fefcfd7ee741803d197167cebae7c9eb864d Mon Sep 17 00:00:00 2001 From: Matthew Hershberger Date: Wed, 19 Jun 2024 12:23:25 -0400 Subject: [PATCH] fix(node): #1180 - Adjust tsconfig compiler options Accidentally applied `es6` when compilerOptions.module was not defined. --- CHANGELOG.md | 2 +- source/runner/runners/utils/transpiler.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) 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