Fix: compute __dirname in vite.config.ts (undefined under ESM)
`__dirname` is undefined in ESM modules, so `path.resolve(__dirname, "./src")` silently produced a bad path in Docker. Locally it happened to work (some Node interop), but the Docker stage hit a clear error: "Could not load /web/src/lib/utils ... ENOENT". Use fileURLToPath(import.meta.url). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+8
-3
@@ -1,9 +1,14 @@
|
|||||||
import path from "path";
|
import path from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import react from "@vitejs/plugin-react";
|
import react from "@vitejs/plugin-react";
|
||||||
|
|
||||||
// During dev (`pnpm dev`), Vite serves on :5173 and proxies /api + /mcp + /health
|
// `__dirname` is undefined in ESM; compute it ourselves so the alias
|
||||||
// to the FastAPI server on :8765 (or PORT env var).
|
// resolves correctly under both local Node and the Docker build.
|
||||||
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
|
// During dev (`npm run dev`), Vite serves on :5173 and proxies /api +
|
||||||
|
// /mcp + /health to the FastAPI server on :8765 (or BACKEND_PORT env).
|
||||||
const BACKEND_PORT = process.env.BACKEND_PORT || "8765";
|
const BACKEND_PORT = process.env.BACKEND_PORT || "8765";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
|||||||
Reference in New Issue
Block a user