hcengineering/platform · error · Error

Missing env variables: ${missingEnv.join(', ')}

Error message

Missing env variables: ${missingEnv.join(', ')}

What it means

pod-notification's config IIFE validates that required Config fields Port and Source are defined, mapping them back to their env var names via envMap. If either is undefined, it throws an error listing the missing env variable names (typically PORT and SOURCE).

Source

Thrown at services/notification/pod-notification/src/config.ts:51

const parseNumber = (str: string | undefined): number | undefined => (str !== undefined ? Number(str) : undefined)

const config: Config = (() => {
  const params: Partial<Config> = {
    Port: parseNumber(process.env[envMap.Port]) ?? 8091,
    Source: process.env[envMap.Source],
    AuthToken: process.env[envMap.AuthToken],
    PushPublicKey: process.env[envMap.PushPublicKey],
    PushPrivateKey: process.env[envMap.PushPrivateKey],
    PushSubject: process.env[envMap.PushSubject]
  }

  const required: Array<keyof Config> = ['Port', 'Source']

  const missingEnv = required.filter((key) => params[key] === undefined).map((key) => envMap[key])

  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

  1. Set all required env vars: PORT (numeric) and SOURCE (source service identifier) per envMap in pod-notification/src/config.ts.
  2. Read the error message — it names the missing variables exactly.
  3. Compare your env file against the service's envMap/README to catch renamed keys.
  4. Confirm the .env/secret is loaded into the process (check container env with `printenv` or `docker exec ... env`).

Example fix

// before
PORT=4004
// after
PORT=4004
SOURCE=notification-service
Defensive patterns

Strategy: validation

Validate before calling

const required = ['PORT', 'SOURCE'];
const missing = required.filter((k) => process.env[k] === undefined || process.env[k] === '');
if (missing.length) {
  throw new Error(`pod-notification missing env vars: ${missing.join(', ')}`);
}

Try / catch

try {
  await import('./config');
} catch (err) {
  if (err instanceof Error && err.message.startsWith('Missing env variables:')) {
    console.error(`pod-notification env incomplete: ${err.message}`);
    process.exit(1);
  }
  throw err;
}

Prevention

When it happens

Trigger: Starting pod-notification with the Port or Source env var unset — e.g. PORT provided but SOURCE missing, or both absent.

Common situations: New deployment missing the notification service's SOURCE variable (often a service identity string); env keys renamed in envMap so older variable names no longer match; local run without the service's .env.

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


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/fc97f366a2873e49. Report an issue: GitHub.