NestJS ConfigModule env var undefined in CI
ConfigService returned undefined because the value it expected came from a .env file that is not committed, and the CI runner has no equivalent environment variable set. Config validation or a downstream provider then fails.
What this error means
The app throws when reading a config value, or validation fails with "Config validation error: X is required", because the variable is absent on the runner.
Error: Config validation error: "DATABASE_URL" is required
at validate (/app/dist/config/env.validation.js:...)Common causes
The .env file is not present in CI
.env is gitignored (correctly), so on the runner the values never load and ConfigService reads undefined.
Variables are not injected into the job environment
No env: block or secrets were mapped to the step, so process.env has none of the expected keys.
How to fix it
Provide env vars via the workflow
- Map required values into the job or step
env:from secrets. - Keep a validation schema so missing keys fail loudly at startup.
- Do not rely on a committed .env for CI secrets.
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}Validate config at bootstrap
Use ConfigModule validation so a missing variable fails fast with a clear message instead of undefined later.
ConfigModule.forRoot({ validationSchema: envSchema, isGlobal: true })How to prevent it
- Inject all required config via workflow env or secrets, never a committed .env.
- Add a validation schema so missing variables fail at startup.
- Document required variables so CI and local stay aligned.