wekan/wekan · error · Meteor.Error

var-not-exist

var-not-exist

Error message

The environment variable ${name} does not exist

What it means

WeKan's settings model reads optional configuration (e.g. Matomo analytics settings) exclusively from environment variables via getEnvVar. Unlike process.env, which silently returns undefined for a missing key, this helper treats a missing variable as a hard configuration error and throws a Meteor.Error with reason 'var-not-exist'. It is thrown on the server while loading Matomo (or similar) config during settings initialization.

Source

Thrown at server/models/settings.js:52

// Security fix (reported by meifukun): invitation codes used to be a 6-digit
// Math.random() value — a ~900,000 keyspace from a NON-cryptographic RNG, with no
// effective throttling on the sign-up validation — so an attacker who knew a
// pending invitee's email could brute-force the code and take the invited account
// (and its private boards). Generate a cryptographically secure 128-bit code
// instead, which cannot be guessed regardless of retry rate. (A DDPRateLimiter
// rule is added in server/models/users.js as defence in depth.)
function generateInvitationCode() {
  const crypto = require('crypto');
  return crypto.randomBytes(16).toString('base64url');
}

function getEnvVar(name) {
  const value = process.env[name];
  if (value) {
    return value;
  }
  throw new Meteor.Error([
    'var-not-exist',
    `The environment variable ${name} does not exist`,
  ]);
}

function loadOidcConfig(service) {
  check(service, String);
  return ServiceConfiguration.configurations.findOneAsync({ service });
}

async function sendInvitationEmail(_id, { isNewInvitation = true } = {}) {
  const icode = await getReactiveCache().getInvitationCode(_id);
  // #4043: never send an invitation email without a code that will validate at
  // sign-up (the sign-up lookup requires { code: <string>, valid: true }).
  // Fail loudly instead of mailing a dead code.
  if (!isInvitationCodeSendable(icode)) {
    throw new Meteor.Error(
      'invitation-code-invalid',

View on GitHub (pinned to eb1433158b)

Solutions

  1. Set the missing environment variable (named in the message) in your deployment environment (docker run -e, compose environment:, systemd Environment=) before starting WeKan
  2. If you do not use Matomo, remove or unset the Matomo-related toggles so getMatomoConf is not invoked, or provide dummy valid values
  3. Check the WeKan docs/Dockerfile for the current expected variable names — names can change between releases
  4. Verify the variable actually reaches the server process (e.g. print env inside the container) — shell sourcing mistakes often leave it unset

Example fix

// before (Dockerfile/compose without Matomo vars)
services:
  wekan:
    image: wekan
// after
services:
  wekan:
    image: wekan
    environment:
      - MATOMO_URL=https://analytics.example.com
      - MATOMO_SITE_ID=1
      - MATOMO_DO_NOT_TRACK=false
Defensive patterns

Strategy: validation

Validate before calling

function hasEnv(name) {
  return typeof process.env[name] === 'string' && process.env[name].length > 0;
}
if (!hasEnv('MATOMO_URL') || !hasEnv('MATOMO_SITE_ID')) {
  throw new Error('MATOMO_URL and MATOMO_SITE_ID must be set');
}

Type guard

function isEnvSet(name) {
  return typeof process.env[name] === 'string' && process.env[name] !== '';
}

Try / catch

try {
  const conf = getMatomoConf();
} catch (e) {
  if (e.reason === 'var-not-exist') {
    console.warn('Missing config env var:', e.message);
    // fall back to disabled analytics
  } else throw e;
}

Prevention

When it happens

Trigger: getEnvVar is called by getMatomoConf for each required Matomo variable (e.g. MATOMO_URL, MATOMO_SITE_ID, MATOMO_DO_NOT_TRACK). If any one of them is unset or set to an empty string, the throw fires immediately — empty string is falsy and counts as missing.

Common situations: Deploying WeKan with Matomo analytics enabled but forgetting to export MATOMO_URL/MATOMO_SITE_ID in the Docker compose file, systemd unit, or snap environment; renaming a variable in a newer WeKan version while the deployment still uses the old name; a CI/container environment dropping env vars declared in an env_file that does not exist.

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 wekan/wekan@eb1433158b (2026-09-01). Data as JSON: /api/errors/22ac1f38922a63b5. Report an issue: GitHub.