diff --git a/next.config.ts b/next.config.ts index b84ce33b8..baad6357d 100644 --- a/next.config.ts +++ b/next.config.ts @@ -9,6 +9,16 @@ const nextConfig: NextConfig = { "@prisma/adapter-pg", "pg", ], + // v1.4.25 Fix-G — `src/lib/ai/prompts/safety-contracts.ts` reads its + // sibling YAML files at runtime via `__dirname + readFileSync`. The + // standalone bundler ships the JS but not the YAML, so the build + // crashed during page-data collection with ENOENT once the Turbopack + // chunking-error layer was cleared. Telling Next to trace the YAML + // files explicitly keeps them in the runtime image alongside the + // bundled module. + outputFileTracingIncludes: { + "*": ["./src/lib/ai/prompts/safety-contracts.*.yaml"], + }, experimental: { optimizePackageImports: ["recharts", "lucide-react"], }, diff --git a/src/lib/ai/prompts/safety-contracts.ts b/src/lib/ai/prompts/safety-contracts.ts index b6bbfb4a1..99c128759 100644 --- a/src/lib/ai/prompts/safety-contracts.ts +++ b/src/lib/ai/prompts/safety-contracts.ts @@ -35,7 +35,13 @@ import { z } from "zod"; import type { Locale } from "@/lib/i18n/config"; -const SAFETY_CONTRACTS_DIR = __dirname; +// Turbopack rewrites `__dirname` to a synthetic `/ROOT/...` token at +// build time, which then fails at runtime when the YAML siblings are +// looked up. Resolving from `process.cwd()` keeps the path stable +// across `next build` + `next start` (and the test runner — vitest sets +// cwd to the repo root). `outputFileTracingIncludes` in `next.config.ts` +// pulls the YAML files into the standalone runtime image. +const SAFETY_CONTRACTS_DIR = join(process.cwd(), "src/lib/ai/prompts"); const ContractEnumsSchema = z.object({ severity: z.array(z.string()).min(1),