pnpm exec knip fails in CI and automated maintenance environments because env.js (powered by @t3-oss/env-nextjs) throws at import time when required environment variables are absent. This blocks knip from performing any analysis.
Error
Invalid environment variables: [
{ path: [ 'DATABASE_URL' ], message: 'Invalid input: expected string, received undefined' },
{ path: [ 'BETTER_AUTH_SECRET' ], ... },
...
]
ERROR: Error loading drizzle.config.ts
Reason: Invalid environment variables
Knip loads drizzle.config.ts as a config entry point, which imports ./env, triggering immediate Zod validation.
Root Cause
Current package.json script:
"knip": "dotenv -e .env.local -- knip"
This requires a .env.local file with real credentials — which does not exist in automated/CI environments.
Fix
@t3-oss/env-nextjs supports SKIP_ENV_VALIDATION=1 to bypass Zod validation. Update the script:
"knip": "SKIP_ENV_VALIDATION=1 dotenv -e .env.local -- knip"
This is safe because knip only performs static AST analysis and never connects to any external service. The SKIP_ENV_VALIDATION flag is the standard T3 stack mechanism for exactly this use case.
Impact
The weekly maintenance workflow cannot run knip to detect dead code, unused exports, or orphaned dependencies. The step silently fails on every automated run.
pnpm exec knipfails in CI and automated maintenance environments becauseenv.js(powered by@t3-oss/env-nextjs) throws at import time when required environment variables are absent. This blocks knip from performing any analysis.Error
Knip loads
drizzle.config.tsas a config entry point, which imports./env, triggering immediate Zod validation.Root Cause
Current
package.jsonscript:This requires a
.env.localfile with real credentials — which does not exist in automated/CI environments.Fix
@t3-oss/env-nextjssupportsSKIP_ENV_VALIDATION=1to bypass Zod validation. Update the script:This is safe because knip only performs static AST analysis and never connects to any external service. The
SKIP_ENV_VALIDATIONflag is the standard T3 stack mechanism for exactly this use case.Impact
The weekly maintenance workflow cannot run knip to detect dead code, unused exports, or orphaned dependencies. The step silently fails on every automated run.