diff --git a/.changeset/five-apricots-happen.md b/.changeset/five-apricots-happen.md new file mode 100644 index 00000000000..3dfc7115534 --- /dev/null +++ b/.changeset/five-apricots-happen.md @@ -0,0 +1,6 @@ +--- +"remix": patch +"@remix-run/dev": patch +--- + +allow setting tsconfig moduleResolution to `node`, `node16`, and `nodenext` diff --git a/integration/tsconfig-test.ts b/integration/tsconfig-test.ts index f0cc4a7e90e..84f49140430 100644 --- a/integration/tsconfig-test.ts +++ b/integration/tsconfig-test.ts @@ -77,6 +77,7 @@ test("shouldn't change suggested config if set", async () => { compilerOptions: { ...DEFAULT_CONFIG.compilerOptions, strict: false, + moduleResolution: "NodeNext", }, }; diff --git a/packages/remix-dev/compiler/utils/tsconfig/write-config-defaults.ts b/packages/remix-dev/compiler/utils/tsconfig/write-config-defaults.ts index b296ee19eef..e77c171bac0 100644 --- a/packages/remix-dev/compiler/utils/tsconfig/write-config-defaults.ts +++ b/packages/remix-dev/compiler/utils/tsconfig/write-config-defaults.ts @@ -23,7 +23,6 @@ let requiredCompilerOptions: TsConfigJson.CompilerOptions = { esModuleInterop: true, isolatedModules: true, jsx: "react-jsx", - moduleResolution: "node", noEmit: true, resolveJsonModule: true, }; @@ -104,6 +103,7 @@ export function writeConfigDefaults(configPath: string) { ); } } + for (let key of objectKeys(requiredCompilerOptions)) { if (fullConfig.compilerOptions[key] !== requiredCompilerOptions[key]) { config.compilerOptions[key] = requiredCompilerOptions[key] as any; @@ -114,6 +114,31 @@ export function writeConfigDefaults(configPath: string) { ); } } + + if (typeof fullConfig.compilerOptions.moduleResolution === "undefined") { + fullConfig.compilerOptions.moduleResolution = "node"; + config.compilerOptions.moduleResolution = "node"; + requiredChanges.push( + colors.blue("compilerOptions.moduleResolution") + + " was set to " + + colors.bold(`'node'`) + ); + } + + if ( + !["node", "node16", "nodenext"].includes( + fullConfig.compilerOptions.moduleResolution.toLowerCase() + ) + ) { + config.compilerOptions.moduleResolution = "node"; + + requiredChanges.push( + colors.blue("compilerOptions.moduleResolution") + + " was set to " + + colors.bold(`'node'`) + ); + } + if (suggestedChanges.length > 0 || requiredChanges.length > 0) { fse.writeFileSync( configPath,