diff --git a/database/context.browser-stub.ts b/database/context.browser-stub.ts new file mode 100644 index 0000000..10f8101 --- /dev/null +++ b/database/context.browser-stub.ts @@ -0,0 +1,9 @@ +// Browser-safe stub for database/context +// The real implementation uses Node.js AsyncLocalStorage which is server-only. +// This stub is used during the client build to avoid bundling server-only code. + +export const DatabaseContext = null as any; + +export function database(): never { + throw new Error("database() can only be called on the server"); +} diff --git a/vite.config.ts b/vite.config.ts index 36dea4b..5855c96 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,8 +1,12 @@ import { reactRouter } from "@react-router/dev/vite"; import tailwindcss from "@tailwindcss/vite"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; import { defineConfig } from "vite"; import tsconfigPaths from "vite-tsconfig-paths"; +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + export default defineConfig(({ isSsrBuild }) => ({ build: { rollupOptions: isSsrBuild @@ -11,6 +15,19 @@ export default defineConfig(({ isSsrBuild }) => ({ } : undefined, }, + resolve: { + alias: isSsrBuild + ? [] + : [ + { + find: "~/database/context", + replacement: path.resolve( + __dirname, + "database/context.browser-stub.ts" + ), + }, + ], + }, plugins: [tailwindcss(), reactRouter(), tsconfigPaths()], server: { allowedHosts: true,