Skip to content

Commit 320cf80

Browse files
committed
fix: replace rxjs with esm bundle
1 parent b7a94b2 commit 320cf80

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

packages/create-sanity/rollup.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ const cliCoreAliases = Object.entries(cliCorePkg.exports as Record<string, unkno
3939
// The commonjs plugin bundles both. Alias to the node entry directly.
4040
const debugNodeEntry = require.resolve('debug/src/node.js')
4141

42+
// rxjs ships ESM under dist/esm but its exports map gates that behind the
43+
// non-standard `es2015` condition — the `node` condition wins and resolves to
44+
// CJS (`dist/cjs/`). Alias rxjs to its ESM source so Rollup can tree-shake it.
45+
const rxjsDir = path.dirname(require.resolve('rxjs/package.json'))
46+
const rxjsEsmDir = path.join(rxjsDir, 'dist', 'esm')
47+
4248
export default defineConfig({
4349
// Catch both `node:fs` and bare `fs` (CJS deps may use unprefixed builtins)
4450
external: (id) => id.startsWith('node:') || builtinModules.includes(id),
@@ -69,6 +75,11 @@ export default defineConfig({
6975
// debug's index.js bundles both browser and node via conditional require.
7076
// Alias to node entry directly since this is a Node CLI tool.
7177
{find: 'debug', replacement: debugNodeEntry},
78+
// Alias rxjs to its ESM build so Rollup can tree-shake it properly.
79+
// Without this, the `node` export condition resolves to CJS.
80+
{find: /^rxjs$/, replacement: path.join(rxjsEsmDir, 'index.js')},
81+
{find: /^rxjs\/operators$/, replacement: path.join(rxjsEsmDir, 'operators', 'index.js')},
82+
{find: /^rxjs\/internal\/(.*)/, replacement: path.join(rxjsEsmDir, 'internal', '$1')},
7283
],
7384
}),
7485
nodeResolve({

0 commit comments

Comments
 (0)