File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,11 +24,25 @@ export default defineConfig({
2424 neverBundle : [ / ^ @ i n t e r n a l / ] ,
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} ) ;
You can’t perform that action at this time.
0 commit comments