santifer/career-ops · error · Error

APIFY_TOKEN not set — enable apify in config/plugins.yml…

Error message

APIFY_TOKEN not set — enable apify in config/plugins.yml and add the token to .env

What it means

The Apify plugin's fetch() requires an Apify API token, read from the plugin context env (ctx.env.APIFY_TOKEN) or process.env.APIFY_TOKEN. If missing, it throws with instructions to enable the plugin in config/plugins.yml and put the token in .env.

Solutions

  1. Add APIFY_TOKEN=<your apify token> to .env at the repo root.
  2. Confirm the plugin is enabled in config/plugins.yml with a valid entry.
  3. Ensure the env loader actually loads .env before scan runs; in CI add APIFY_TOKEN to secrets.
  4. Restart the process after editing .env — some runners cache env at startup.

Example fix

// before
# .env (no apify token)
// after
APIFY_TOKEN=apify_api_XXXXXXXXXXXXXXXX
Defensive patterns

Strategy: validation

Validate before calling

const token = ctx?.env?.APIFY_TOKEN || process.env.APIFY_TOKEN;
if (!token) throw new Error('apify plugin needs APIFY_TOKEN in .env');

Try / catch

try {
  await scan(entry);
} catch (e) {
  if (String(e.message).includes('APIFY_TOKEN not set')) {
    console.error('Enable apify in config/plugins.yml and add APIFY_TOKEN to .env');
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Running a scan with the apify plugin configured/enabled but no APIFY_TOKEN in .env or the plugin ctx.env; token present under a different variable name.

Common situations: Fresh checkout where .env was never created; enabling the plugin in config/plugins.yml but forgetting the token; CI pipeline missing the secret; docker container without env passthrough.

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 santifer/career-ops@aac998c7ed (2026-09-16). Data as JSON: /api/errors/f10ad63760858829. Report an issue: GitHub.

Appendix: source

Thrown at plugins/apify/index.mjs:182

  };
  for (const [k, v] of Object.entries(defaults || {})) {
    if (!ALLOWED_DEFAULT_KEYS.has(k)) continue;
    if (!out[k]) out[k] = String(v);
  }
  return out;
}

/** The keyed provider hook. Reads APIFY_TOKEN from the plugin's scoped ctx.env. */
export default {
  provider: {
    id: 'apify',
    // Keyed providers never auto-detect (the engine also forces this to null).
    detect() { return null; },

    async fetch(entry, ctx) {
      const token = ctx?.env?.APIFY_TOKEN || process.env.APIFY_TOKEN;
      if (!hasToken(token)) {
        throw new Error('APIFY_TOKEN not set — enable apify in config/plugins.yml and add the token to .env');
      }
      if (!entry.actor) {
        throw new Error(`apify: entry ${entry.name} missing 'actor' (e.g. misceres/indeed-scraper)`);
      }
      if (
        !entry.field_map ||
        !isFieldSpec(entry.field_map.title) ||
        !isFieldSpec(entry.field_map.url) ||
        (entry.field_map.company != null && !isFieldSpec(entry.field_map.company)) ||
        (entry.field_map.location != null && !isFieldSpec(entry.field_map.location)) ||
        (entry.field_map.description != null && !isFieldSpec(entry.field_map.description))
      ) {
        throw new Error(
          `apify: entry ${entry.name} has invalid field_map. Each of title, url, company, ` +
          `location, description must be a string or a non-empty array of strings. title and url are required.`
        );
      }

View on GitHub (pinned to aac998c7ed)