diff --git a/.changeset/v2-serve-dynamic-import.md b/.changeset/v2-serve-dynamic-import.md new file mode 100644 index 00000000000..f3cd5159f11 --- /dev/null +++ b/.changeset/v2-serve-dynamic-import.md @@ -0,0 +1,5 @@ +--- +"@remix-run/serve": major +--- + +Preserve dynamic imports in remix-serve for external bundle diff --git a/packages/remix-serve/rollup.config.js b/packages/remix-serve/rollup.config.js index 59886138ce2..5ed2ee66468 100644 --- a/packages/remix-serve/rollup.config.js +++ b/packages/remix-serve/rollup.config.js @@ -38,6 +38,17 @@ module.exports = function rollup() { extensions: [".ts", ".tsx"], }), nodeResolve({ extensions: [".ts", ".tsx"] }), + // Allow dynamic imports in CJS code to allow us to utilize + // ESM modules as part of the compiler. + { + name: "dynamic-import-polyfill", + renderDynamicImport() { + return { + left: "import(", + right: ")", + }; + }, + }, copy({ targets: [ { src: "LICENSE.md", dest: [outputDir, sourceDir] },