fix(env): skip validation during next build static analysis #2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/env-validation-skip"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Vervolg-fix op PR #1 (al gemerged) voor M16 fase 1 task 16 build-blocker.
Na de prisma-dir fix komt de Docker-build verder maar
next buildfaalt oplib/env.tsmodule-load:nextdoet static analysis die modules importeert, enlib/env.tsthrowt alsDATABASE_URL/WORKERS_SESSION_SECRETmissen (die landen pas at-runtime via docker-compose env_file).Fix
Twee escape-hatches in
lib/env.ts:Plus
ENV SKIP_ENV_VALIDATION=1in Dockerfile builder-stage vóórRUN npm run build.Runtime (dev/start/test) blijft volledig valideren — alleen
next buildstatic-analysis krijgt de bypass. Bij SKIP wordt env een leeg object cast naar Env; build-time consumers die env.X lezen krijgen undefined (acceptabel — runtime via env_file is altijd valid).Test plan
SKIP_ENV_VALIDATION=1 tsx import lib/env.ts→ env={} no thrownpm run verify→ 15/15 tests passing, typecheck clean, lint clean (tests gebruiken tests/setup.ts die env-stubs zet, dus validation runt en passeert)Server-Claude retry:
Verwacht: build slaagt door alle RUN-lines inclusief
npm run build.Context
Deel 2/2 van M16 fase 1 task 16 build-blockers (deel 1 was PR #1 prisma-dir fix, al gemerged in
54f9693).next buildstatic analysis ffaeba50e8next build does a production-build pass that imports modules to collect route metadata. lib/env.ts throws on module-load if DATABASE_URL or WORKERS_SESSION_SECRET are missing — at build time they aren't (they land at runtime via docker-compose env_file). Two escape hatches, both checked: 1. NEXT_PHASE=phase-production-build (set automatically by next build) 2. SKIP_ENV_VALIDATION=1 (explicit, set in Dockerfile builder stage) When SKIP is active and parsing fails, env is exported as {} cast to Env. Build-time consumers reading env.X get undefined — acceptable because real runtime always has the env_file values. Tests still set defaults via __tests__/setup.ts so validation runs and passes there. Tested: - SKIP_ENV_VALIDATION=1 tsx import → env={} no throw - DATABASE_URL+WORKERS_SESSION_SECRET set → env populated - npm run verify → 15/15 tests passing, typecheck clean, lint clean