Skip to content

Commit ea892cf

Browse files
committed
fix redis-worker
1 parent a04162f commit ea892cf

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

packages/redis-worker/tsdown.config.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,25 @@ export default defineConfig({
2424
neverBundle: [/^@internal/],
2525
},
2626
},
27-
banner: ({ format }) => {
28-
if (format !== "esm") return;
29-
30-
return {
31-
js: `import { createRequire } from 'module'; const require = createRequire(import.meta.url || process.cwd() + '/index.js');`,
32-
};
33-
},
27+
// rolldown injects its own `__require` helper in the ESM output as
28+
// `createRequire(import.meta.url)` with no fallback. When this ESM bundle is
29+
// re-bundled into a CJS consumer (e.g. the webapp server), esbuild replaces
30+
// `import.meta.url` with `undefined`, so `createRequire(undefined)` throws at
31+
// startup. Patch the helper to fall back to a valid path, matching the
32+
// fallback the previous tsup banner provided.
33+
plugins: [
34+
{
35+
name: "resilient-create-require",
36+
renderChunk(code: string) {
37+
if (!code.includes("createRequire(import.meta.url)")) return null;
38+
return {
39+
code: code.replaceAll(
40+
"createRequire(import.meta.url)",
41+
"createRequire(import.meta.url || process.cwd() + '/index.js')"
42+
),
43+
map: null,
44+
};
45+
},
46+
},
47+
],
3448
});

0 commit comments

Comments
 (0)