Skip to content
Latchkey

Firebase "emulators:exec ... exited with code 1" in CI

The emulators started fine; the command you passed to emulators:exec returned a non-zero exit code. emulators:exec forwards that exit code, so the failure is in your test or script, not the emulator itself.

What this error means

A CI step fails with "Script exited with code 1" or "emulators:exec: Script exited with non-zero code" after the emulators booted.

firebase
i  emulators: Shutting down emulators.
Error: Script exited with code 1

Common causes

The wrapped tests failed

Your test command returned 1, which emulators:exec propagates as its own exit code.

The tests target the wrong emulator host

If the app connects to production instead of the emulator, tests fail against unexpected data.

How to fix it

Read your command output, not the emulator log

  1. Scroll to the test output printed before the shutdown line.
  2. Fix the failing test or script.
  3. Confirm the app points at the emulator host and ports.
Terminal
firebase emulators:exec --only firestore,auth "npm test"

Point the SDK at the emulators

Set the emulator host env vars so your code connects to the emulator during the run.

.github/workflows/ci.yml
env:
  FIRESTORE_EMULATOR_HOST: 127.0.0.1:8080
  FIREBASE_AUTH_EMULATOR_HOST: 127.0.0.1:9099

How to prevent it

  • Treat a non-zero exit as a real test failure, not an emulator bug.
  • Set emulator host env vars so tests hit the emulator.
  • Keep emulator ports consistent between config and env vars.

Related guides

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