Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.
This repository was archived by the owner on Apr 2, 2026. It is now read-only.

chore: fix knip failing in CI due to missing env vars #269

Description

@claude

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions