santifer/career-ops · error · Error

no local H-1B index and no H1B_API_BASE. Install the index…

Error message

no local H-1B index and no H1B_API_BASE. Install the index with: node plugins/h1b-sponsor/install-h1b-index.mjs (about 8 MiB of public DOL data; lookups then stay on this machine). To use an HTTP endpoint instead, set H1B_API_BASE to one you trust.

What it means

The H-1B sponsor plugin needs a data backend: either a locally installed SQLite index of public DOL data, or a remote HTTP endpoint configured via H1B_API_BASE. selectBackend throws when neither is present, i.e. no local index files were found on disk and no H1B_API_BASE environment variable is set. The message includes the exact install command.

Solutions

  1. Run `node plugins/h1b-sponsor/install-h1b-index.mjs` to download and install the local index (~8 MiB of public DOL data).
  2. Alternatively set H1B_API_BASE to a trusted HTTP endpoint, e.g. export H1B_API_BASE=https://your-h1b-api.example.com, if you prefer remote lookups.
  3. Verify the install actually wrote the index files to the expected location (re-run the installer; it is idempotent).

Example fix

// before (shell)
node plugins/h1b-sponsor/check.mjs "Acme Corp"   # throws
// after
node plugins/h1b-sponsor/install-h1b-index.mjs
node plugins/h1b-sponsor/check.mjs "Acme Corp"
Defensive patterns

Strategy: fallback

Validate before calling

import { existsSync } from 'node:fs';
const localReady = existsSync('plugins/h1b-sponsor/index.sqlite');
const remoteReady = Boolean(process.env.H1B_API_BASE);
if (!localReady && !remoteReady) {
  throw new Error('Run node plugins/h1b-sponsor/install-h1b-index.mjs or set H1B_API_BASE');
}

Type guard

const backendAvailable = () =>
  Boolean(process.env.H1B_API_BASE) || hasLocalIndex();

Try / catch

try {
  const backend = await selectBackend();
} catch (e) {
  if (e.message.includes('no local H-1B index')) {
    console.error('Install the index first: node plugins/h1b-sponsor/install-h1b-index.mjs');
    process.exit(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling any employer lookup (resolveEmployer/searchEmployers/getEmployerProfile via check.mjs) on a machine where install-h1b-index.mjs was never run and the H1B_API_BASE env var is unset.

Common situations: Fresh checkout or CI environment where the one-time index install was skipped; the index was installed under a different path than the backend expects; a user intended to use the HTTP backend but forgot to export H1B_API_BASE.

Related errors


AI-assisted analysis of santifer/career-ops@aac998c7ed (2026-09-16). Data as JSON: /api/errors/649eb3cdf023d868. Report an issue: GitHub.

Appendix: source

Thrown at plugins/h1b-sponsor/check.mjs:80

      opts: token ? { token } : {},
      resolveEmployer: httpBackend.resolveEmployer,
      searchEmployers: httpBackend.searchEmployers,
      getEmployerProfile: httpBackend.getEmployerProfile,
    };
  }
  if (localBackend.hasIndex()) {
    return {
      kind: 'index',
      // The index digest, so a cached answer is tied to the exact data that
      // produced it and a refreshed index invalidates the old numbers.
      source: await localBackend.indexSource(),
      opts: {},
      resolveEmployer: localBackend.resolveEmployer,
      searchEmployers: localBackend.searchEmployers,
      getEmployerProfile: localBackend.getEmployerProfile,
    };
  }
  throw new Error(
    'no local H-1B index and no H1B_API_BASE. Install the index with: node plugins/h1b-sponsor/install-h1b-index.mjs '
    + '(about 8 MiB of public DOL data; lookups then stay on this machine). To use an HTTP endpoint instead, '
    + 'set H1B_API_BASE to one you trust.',
  );
}

// Where the answer came from, reported back to the caller. The HTTP path names
// the employer's own URL so the number can be checked by hand; the local path
// names the index build, which is the equivalent handle for data on disk.
function sourceRef(employerId) {
  if (!backend) return null;
  if (backend.kind === 'index') return backend.source;
  return employerId
    ? `${backend.source}/employers/${encodeURIComponent(employerId)}`
    : `${backend.source}/employers`;
}

// Text from the backend goes through this before any non-JSON output, whether

View on GitHub (pinned to aac998c7ed)