{"record":{"id":"a5a65fea34083d80","repo":"MiniMax-AI/skills","slug":"missing-required-env-var-name","errorCode":null,"errorMessage":"Missing required env var: ${name}","messagePattern":"Missing required env var: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"skills/fullstack-dev/SKILL.md","lineNumber":266,"sourceCode":"```\n\n---\n\n## 2. Configuration & Environment (CRITICAL)\n\n### Centralized, Typed, Fail-Fast\n\n**TypeScript:**\n```typescript\nconst config = {\n  port: parseInt(process.env.PORT || '3000', 10),\n  database: { url: requiredEnv('DATABASE_URL'), poolSize: intEnv('DB_POOL_SIZE', 10) },\n  auth: { jwtSecret: requiredEnv('JWT_SECRET'), expiresIn: process.env.JWT_EXPIRES_IN || '1h' },\n} as const;\n\nfunction requiredEnv(name: string): string {\n  const value = process.env[name];\n  if (!value) throw new Error(`Missing required env var: ${name}`);  // fail fast\n  return value;\n}\n```\n\n**Python:**\n```python\nfrom pydantic_settings import BaseSettings\n\nclass Settings(BaseSettings):\n    database_url: str                        # required — app won't start without it\n    jwt_secret: str                          # required\n    port: int = 3000                         # optional with default\n    db_pool_size: int = 10\n    class Config:\n        env_file = \".env\"\n\nsettings = Settings()                        # fails fast if DATABASE_URL missing\n```","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/MiniMax-AI/skills/blob/60aaae52bb2af8162732751a4332f62a5fef518b/skills/fullstack-dev/SKILL.md#L248-L284","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set the named variable in the environment: `export DATABASE_URL='postgres://...'` (use the exact name from the error message) and restart.","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`).","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).","Confirm the variable name spelling matches exactly — the message echoes the name passed to `requiredEnv`, so compare it against your `.env` keys."],"exampleFix":"// before (fails if .env not loaded)\nimport { config } from './config';\n\n// after — load env before importing config\nimport 'dotenv/config';\nimport { config } from './config';\n// and ensure .env contains: DATABASE_URL=postgres://user:pass@host:5432/db","handlingStrategy":"validation","validationCode":"// Validate all required env at startup with a single schema, fail with a clear report.\nimport 'dotenv/config';\nconst required = ['DATABASE_URL', 'JWT_SECRET'] as const;\nconst missing = required.filter(k => !process.env[k]);\nif (missing.length) {\n  console.error(`Missing required env vars: ${missing.join(', ')}`);\n  process.exit(1);\n}\n// now safe to build config","typeGuard":"const isNonEmpty = (v: string | undefined): v is string =>\n  typeof v === 'string' && v.trim().length > 0;\n\nfunction requiredEnv(name: string): string {\n  const v = process.env[name];\n  if (!isNonEmpty(v)) throw new Error(`Missing required env var: ${name}`);\n  return v;\n}","tryCatchPattern":"// Wrap bootstrap so a missing var becomes a clean shutdown, not a crash mid-request.\ntry {\n  const { config } = await import('./config');\n  app.listen(config.port);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Missing required env var')) {\n    console.error(e.message);\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Keep one canonical list of required env vars and validate it in a single startup module before any other import.","Load dotenv at the very entry point so config modules see populated values.","Use a typed config library (zod, envalid, pydantic-settings) to fail fast with a structured error listing all missing vars at once.","Provide a `.env.example` checked into the repo listing every required variable."],"tags":["typescript","config","env","fail-fast","startup"],"backgroundTag":null,"analyzedSha":"60aaae52bb2af8162732751a4332f62a5fef518b","analyzedAt":"2026-08-13T17:32:34.717Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}