hcengineering/platform · error · Error

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

Error message

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

What it means

The rekoni service config module validates required environment variables at startup (module-level IIFE) and throws synchronously if any required value resolves to undefined. The message lists the missing env variable names from envMap, making it a startup-time fail-fast guard.

Source

Thrown at services/rekoni/src/config.ts:44

  ServiceID: 'SERVICE_ID',
  Secret: 'SECRET'
}

const required: Array<keyof Config> = ['ServiceID', 'Secret']

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] ?? '4004'),
    ServiceID: process.env[envMap.ServiceID] ?? 'rekoni-service',
    Secret: process.env[envMap.Secret] ?? 'secret'
  }

  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. Read the missing variable names from the error and set them in the deployment environment (.env, docker-compose, k8s manifest).
  2. Check services/rekoni/src/config.ts for the required keys and envMap to get exact variable names.
  3. If a variable is optional in your setup, add a default with ?? in the params object.
  4. Restart the service after setting the variables — config is computed once at import time.

Example fix

// before (deploy env)
REKONI_ENDPOINT=https://rekoni
# SECRET_TOKEN missing
// after (deploy env)
REKONI_ENDPOINT=https://rekoni
SECRET_TOKEN=xxxx
Defensive patterns

Strategy: validation

Validate before calling

// run before importing the service
const required = ['REKONI_ENDPOINT', 'SECRET_TOKEN'] // mirror config.ts required/envMap
const missing = required.filter((k) => process.env[k] === undefined)
if (missing.length > 0) throw new Error(`Missing env: ${missing.join(', ')}`)

Type guard

function hasEnv(keys: string[]): boolean { return keys.every((k) => process.env[k] !== undefined) }

Try / catch

try {
  await import('./config.js') // config throws at module load
} catch (err) {
  if (err.message.startsWith('Missing env variables:')) {
    console.error('Set the listed env vars and restart:', err.message)
    process.exit(1)
  }
  throw err
}

Prevention

When it happens

Trigger: Starting services/rekoni without setting one of the required env variables listed in envMap/required. Only required keys without a ?? default trigger this; Secret has a 'secret' fallback here, so other required keys are the usual culprits.

Common situations: Docker/Kubernetes deployments with missing env entries, a .env file not loaded, typos in env variable names, or a newly added required config key after upgrading the service.

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/dac31dd47049cbad. Report an issue: GitHub.