diff --git a/tsup.config.ts b/tsup.config.ts index 6624b1d..82f0b2e 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -7,5 +7,20 @@ export default defineConfig({ entry: ["src/**/*.ts", "!src/**/*.test.*"], format: ["cjs", "esm"], outDir: "lib", + plugins: [ + { + name: "fix-cjs", + renderChunk(_, chunk) { + if (this.format === "esm") { + // replace `from '...js'` with `from '...mjs'` for mjs imports & exports + const code = chunk.code.replace( + /from ['"](.*)\.js['"]/g, + "from '$1.mjs'", + ); + return { code }; + } + }, + }, + ], sourcemap: true, });