hcengineering/platform · error · Error
Missing env variables: ${missingEnv.join(', ')}
Error message
Missing env variables: ${missingEnv.join(', ')} What it means
The pod-ai-bot config IIFE validates that no Config field is undefined and throws at import time otherwise. Most fields have defaults; only ACCOUNTS_URL, MONGO_URL, SERVER_SECRET, FIRST_NAME and LAST_NAME lack fallbacks, so those are the values that can actually trigger the throw.
Source
Thrown at services/ai-bot/pod-ai-bot/src/config.ts:82
OpenAITranslateModel: (process.env.OPENAI_TRANSLATE_MODEL ?? 'gpt-4o-mini') as OpenAI.ChatModel,
OpenAISummaryModel: (process.env.OPENAI_SUMMARY_MODEL ?? 'gpt-4o-mini') as OpenAI.ChatModel,
OpenAIBaseUrl: process.env.OPENAI_BASE_URL ?? '',
MaxContentTokens: parseNumber(process.env.MAX_CONTENT_TOKENS) ?? 128 * 100,
MaxHistoryRecords: parseNumber(process.env.MAX_HISTORY_RECORDS) ?? 500,
Port: parseNumber(process.env.PORT) ?? 4010,
LoveEndpoint: process.env.LOVE_ENDPOINT ?? '',
DataLabApiKey: process.env.DATALAB_API_KEY ?? '',
BillingUrl: process.env.BILLING_URL ?? '',
DeepgramPollIntervalMinutes: parseNumber(process.env.DEEPGRAM_POLL_INTERVAL_MINUTES) ?? 60,
DeepgramApiKey: process.env.DEEPGRAM_API_KEY ?? '',
DeepgramProjectId: process.env.DEEPGRAM_PROJECT_ID ?? '',
DeepgramTag: process.env.DEEPGRAM_TAG ?? ''
}
const missingEnv = (Object.keys(params) as Array<keyof Config>).filter((key) => params[key] === undefined)
if (missingEnv.length > 0) {
throw Error(`Missing env variables: ${missingEnv.join(', ')}`)
}
return params as Config
})()
export default config
View on GitHub (pinned to 63e28dc964)
Solutions
- Set the env vars named in the message — typically MONGO_URL, SERVER_SECRET, ACCOUNTS_URL, FIRST_NAME, LAST_NAME.
- Check k8s ConfigMap/Secret references actually exist and keys match exactly.
- Create a local .env covering these five vars before running the bot.
- If a var should be optional, add a `??` default in src/config.ts and it will stop being reported.
Example fix
// before FIRST_NAME=Huly # MONGO_URL missing // after ACCOUNTS_URL=https://accounts.example.com MONGO_URL=mongodb://mongo:27017 SERVER_SECRET=... FIRST_NAME=Huly LAST_NAME=AI
Defensive patterns
Strategy: validation
Validate before calling
const required = ['ACCOUNTS_URL','MONGO_URL','SERVER_SECRET','FIRST_NAME','LAST_NAME']
const missing = required.filter((k) => process.env[k] === undefined)
if (missing.length > 0) throw new Error(`Missing env variables: ${missing.join(', ')}`) Type guard
function hasEnv(key: string): boolean {
return process.env[key] !== undefined
} Try / catch
try {
const { default: config } = await import('./config.js')
} catch (err) {
if ((err as Error).message.startsWith('Missing env variables:')) {
console.error('ai-bot config error:', err.message)
process.exit(1)
}
throw err
} Prevention
- List the five required vars (ACCOUNTS_URL, MONGO_URL, SERVER_SECRET, FIRST_NAME, LAST_NAME) in .env.example.
- Verify ConfigMap/Secret key spelling during deployment review.
- Add a startup preflight that checks required env before importing the service.
- Use the same SERVER_SECRET value across services that must interoperate.
When it happens
Trigger: Importing services/ai-bot/pod-ai-bot/src/config.ts without one of: ACCOUNTS_URL, MONGO_URL, SERVER_SECRET, FIRST_NAME, LAST_NAME. The error lists the Config keys, e.g. 'MongoURL, ServerSecret'.
Common situations: Deploying ai-bot without a MongoDB URL or server secret; forgetting the bot identity vars FIRST_NAME/LAST_NAME; local run without .env; ConfigMap trimmed during a redeploy.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- Missing env variables: ${missingEnv.join(', ')}
- Missing config for attributes: ${missingEnv.join(', ')}
- Missing config for attributes: ${missingEnv.join(', ')}
- Missing config for attributes: ${missingEnv.join(', ')}
- Missing env variables: ${missingEnv.join(', ')}
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/3b9b3ecb280c6843.
Report an issue: GitHub.