MiniMax-AI/skills · critical · Error

Missing required env var: ${name}

Error message

Missing required env var: ${name}

What it means

Thrown by the `requiredEnv(name)` helper inside a TypeScript fail-fast config object. It is invoked for variables marked required (e.g. DATABASE_URL, JWT_SECRET) so the process aborts immediately at startup if a required environment variable is unset or empty. The library pattern here is the application's own bootstrap, not a third-party runtime — the throw exists deliberately to make misconfiguration loud and early rather than producing a half-working server.

Source

Thrown at skills/fullstack-dev/SKILL.md:266

```

---

## 2. Configuration & Environment (CRITICAL)

### Centralized, Typed, Fail-Fast

**TypeScript:**
```typescript
const config = {
  port: parseInt(process.env.PORT || '3000', 10),
  database: { url: requiredEnv('DATABASE_URL'), poolSize: intEnv('DB_POOL_SIZE', 10) },
  auth: { jwtSecret: requiredEnv('JWT_SECRET'), expiresIn: process.env.JWT_EXPIRES_IN || '1h' },
} as const;

function requiredEnv(name: string): string {
  const value = process.env[name];
  if (!value) throw new Error(`Missing required env var: ${name}`);  // fail fast
  return value;
}
```

**Python:**
```python
from pydantic_settings import BaseSettings

class Settings(BaseSettings):
    database_url: str                        # required — app won't start without it
    jwt_secret: str                          # required
    port: int = 3000                         # optional with default
    db_pool_size: int = 10
    class Config:
        env_file = ".env"

settings = Settings()                        # fails fast if DATABASE_URL missing
```

View on GitHub (pinned to 60aaae52bb)

Solutions

  1. Set the named variable in the environment: `export DATABASE_URL='postgres://...'` (use the exact name from the error message) and restart.
  2. If using a `.env` file, ensure it exists at the project root and is loaded before the config module imports (e.g. `import 'dotenv/config'` at the top of the entry file, or run with `node -r dotenv/config`).
  3. Verify the variable is actually exported in the active shell with `printenv DATABASE_URL` (note: a child process will not inherit an unset var even if you think you exported it).
  4. Confirm the variable name spelling matches exactly — the message echoes the name passed to `requiredEnv`, so compare it against your `.env` keys.

Example fix

// before (fails if .env not loaded)
import { config } from './config';

// after — load env before importing config
import 'dotenv/config';
import { config } from './config';
// and ensure .env contains: DATABASE_URL=postgres://user:pass@host:5432/db
Defensive patterns

Strategy: validation

Validate before calling

// Validate all required env at startup with a single schema, fail with a clear report.
import 'dotenv/config';
const required = ['DATABASE_URL', 'JWT_SECRET'] as const;
const missing = required.filter(k => !process.env[k]);
if (missing.length) {
  console.error(`Missing required env vars: ${missing.join(', ')}`);
  process.exit(1);
}
// now safe to build config

Type guard

const isNonEmpty = (v: string | undefined): v is string =>
  typeof v === 'string' && v.trim().length > 0;

function requiredEnv(name: string): string {
  const v = process.env[name];
  if (!isNonEmpty(v)) throw new Error(`Missing required env var: ${name}`);
  return v;
}

Try / catch

// Wrap bootstrap so a missing var becomes a clean shutdown, not a crash mid-request.
try {
  const { config } = await import('./config');
  app.listen(config.port);
} catch (e) {
  if (e instanceof Error && e.message.startsWith('Missing required env var')) {
    console.error(e.message);
    process.exit(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: Any `requiredEnv('DATABASE_URL')` or `requiredEnv('JWT_SECRET')` call where `process.env[name]` is `undefined` or an empty string. This runs during module evaluation when `config` is first imported, so the error fires before the server binds a port.

Common situations: Missing `.env` file, forgetting to load it with dotenv, running in an environment (CI, container, production host) where the secret was never injected, or a typo in the variable name between the shell and `requiredEnv`. Also after renaming a variable in code without updating the deployment manifest.

Related errors


AI-assisted analysis of MiniMax-AI/skills@60aaae52bb (2026-08-13). Data as JSON: /api/errors/a5a65fea34083d80. Report an issue: GitHub.