@@ -15,8 +15,46 @@ function htmlBaseUrl(): Plugin {
1515 } ;
1616}
1717
18+ /**
19+ * Rollup plugin: stub Node.js built-in modules that leak into the browser
20+ * bundle via server-side transitive dependencies (e.g. @objectstack/core
21+ * imports "crypto" and "path").
22+ *
23+ * Each built-in is resolved to a virtual module whose default export is an
24+ * empty object and every named import becomes a no-op function, so that
25+ * `import { createHash } from "crypto"` does not crash the build.
26+ */
27+ const nodeBuiltins = [ 'crypto' , 'path' ] ;
28+ const VIRTUAL_PREFIX = '\0node-stub:' ;
29+ function nodeBuiltinStubs ( ) : Plugin {
30+ return {
31+ name : 'node-builtin-stubs' ,
32+ enforce : 'pre' ,
33+ resolveId ( source ) {
34+ if ( nodeBuiltins . includes ( source ) ) return VIRTUAL_PREFIX + source ;
35+ } ,
36+ load ( id ) {
37+ if ( id . startsWith ( VIRTUAL_PREFIX ) ) {
38+ // Proxy-based default that returns no-op for any property access;
39+ // explicit named exports for identifiers Rollup needs to resolve
40+ // statically during tree-shaking.
41+ return `
42+ const noop = () => '';
43+ const chainable = () => ({ update: chainable, digest: noop });
44+ export default new Proxy({}, { get: () => noop });
45+ export const createHash = chainable;
46+ export const resolve = noop;
47+ export const join = noop;
48+ export const dirname = noop;
49+ export const basename = noop;
50+ ` ;
51+ }
52+ } ,
53+ } ;
54+ }
55+
1856export default defineConfig ( {
19- plugins : [ react ( ) , tailwindcss ( ) , htmlBaseUrl ( ) ] ,
57+ plugins : [ react ( ) , tailwindcss ( ) , htmlBaseUrl ( ) , nodeBuiltinStubs ( ) ] ,
2058 base,
2159 resolve : {
2260 // Ensure every dependency resolves to exactly ONE copy of React, its DOM
@@ -32,11 +70,15 @@ export default defineConfig({
3270 'react' ,
3371 'react-dom' ,
3472 'react-dom/client' ,
73+ 'react-router' ,
3574 'react-router-dom' ,
3675 'better-auth/react' ,
3776 'better-auth/client/plugins' ,
3877 '@tanstack/react-query' ,
3978 ] ,
79+ // @objectstack /core contains Node.js built-ins (crypto, path).
80+ // Exclude it from pre-bundling so the stubs plugin resolves them.
81+ exclude : [ '@objectstack/core' ] ,
4082 } ,
4183 server : {
4284 port : 5321 ,
0 commit comments