database/context.ts uses AsyncLocalStorage from node:async_hooks which is a Node.js-only API. Vite externalizes it for browser builds but the resulting error "AsyncLocalStorage is not exported by __vite-browser-external" caused npm run build to fail. Fix: add a Vite resolve.alias for the browser (non-SSR) build that maps ~/database/context to a browser-safe stub. The stub is never called at runtime since database() is only invoked in server-side loaders, but it allows the client bundle to build without errors. https://claude.ai/code/session_01Fjf9WFqNnuHmmC5yTedL7G Co-authored-by: Claude <noreply@anthropic.com>
35 lines
866 B
TypeScript
35 lines
866 B
TypeScript
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
|
|
? {
|
|
input: "./server/app.ts",
|
|
}
|
|
: undefined,
|
|
},
|
|
resolve: {
|
|
alias: isSsrBuild
|
|
? []
|
|
: [
|
|
{
|
|
find: "~/database/context",
|
|
replacement: path.resolve(
|
|
__dirname,
|
|
"database/context.browser-stub.ts"
|
|
),
|
|
},
|
|
],
|
|
},
|
|
plugins: [tailwindcss(), reactRouter(), tsconfigPaths()],
|
|
server: {
|
|
allowedHosts: true,
|
|
},
|
|
}));
|