Skip to content
Latchkey

Node "process.exit called with code 1" Fails the Job in CI - Trace the Cause

A non-zero process.exit(1) is a deliberate failure signal. CI treats any non-zero exit as a failed step, so the question is which condition tripped the exit.

What this error means

A node script ends the job with exit code 1, sometimes with little output, because code called process.exit(1) on a validation, missing config, or caught error.

node
> node scripts/check-env.js

Missing required env var: DATABASE_URL
Error: Process completed with exit code 1.

Common causes

A guard script exits on a failed precondition

A check script calls process.exit(1) when a required env var, file, or condition is absent in CI.

A caught error is rethrown as an exit

A try/catch logs the error and calls process.exit(1), hiding the original stack behind the exit code.

How to fix it

Read the message before the exit

  1. Find the process.exit(1) call and the log line printed just before it.
  2. Fix the failing precondition (set the env var, provide the file).

Surface the underlying error

  1. Log the full error before exiting so CI shows the real cause.
  2. Prefer setting process.exitCode and letting the process end naturally.
JavaScript
catch (err) {
  console.error(err);
  process.exitCode = 1;
}

How to prevent it

  • Make exit-on-failure scripts log a clear reason, prefer process.exitCode over an abrupt exit so flushing completes, and document the preconditions CI must satisfy.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →