Firebase Auth emulator "ECONNREFUSED" in CI
The test suite tried to reach the Firebase Auth emulator on 127.0.0.1:9099 but the connection was refused. The emulator was not yet listening, or it bound a different host or port.
What this error means
Auth tests fail with "Error: connect ECONNREFUSED 127.0.0.1:9099". The emulator was started but tests ran before it was ready, or the configured port does not match.
Firebase emulator
Error: connect ECONNREFUSED 127.0.0.1:9099
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)Common causes
Tests ran before the emulator was ready
The emulator takes a moment to bind its port; tests started too early get connection refused.
A port or host mismatch
The emulator bound a different port than the env expects, so the client connects nowhere.
How to fix it
Run tests via emulators:exec
- Wrap the test command in firebase emulators:exec so it waits for readiness.
- Set the emulator host env to match the started port.
- Do not launch tests in parallel with the emulator start.
Terminal
firebase emulators:exec --only auth "npm test"Match the configured emulator port
Align firebase.json emulator ports with FIREBASE_AUTH_EMULATOR_HOST so the client hits the right port.
How to prevent it
- Use emulators:exec so tests wait for the emulator.
- Keep firebase.json ports and the host env in sync.
- Avoid racing test start against emulator start.
Related guides
Firebase Auth "auth/invalid-api-key" in CIFix Firebase Auth "auth/invalid-api-key" in CI - the Firebase config apiKey passed to initializeApp was missi…
Keycloak "Connection refused" service not ready in CIFix Keycloak "Connection refused" in CI - the test suite hit the Keycloak service container before it finishe…
Cognito "NotAuthorizedException: Incorrect username or password" in CIFix Cognito "NotAuthorizedException: Incorrect username or password" in CI - the InitiateAuth call used wrong…