mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 20:42:43 +00:00
fix(build): resolve safety-contracts YAML path from cwd, not __dirname
Turbopack rewrites `__dirname` to a synthetic `/ROOT/...` token at build time, so `readFileSync(join(__dirname, 'safety-contracts.fr.yaml'))` crashed during page-data collection in the Docker build with an ENOENT. The chunk error fixed in the previous commit was hiding the issue. The path now resolves through `process.cwd() + 'src/lib/ai/prompts'`, which stays stable across `next build`, `next start`, and the test runner. `outputFileTracingIncludes` in `next.config.ts` pulls the YAML siblings into the standalone runtime image so the read succeeds at deploy time.
This commit is contained in:
1 parent
e51a4f53bb
commit
dd44a0df49
2 files changed
+17
-1
No files matched your search
@@ -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"],
|
||||
},
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in new issue
Block a user