Skip to content
Latchkey

Cypress "cy.visit() failed ... ECONNREFUSED" in CI

cy.visit() tried to open the URL but the connection was refused, meaning nothing was listening there yet. In CI this is the app server not being ready before the test started, or a baseUrl pointing at the wrong port.

What this error means

A test fails with "cy.visit() failed trying to load: http://localhost:3000/ ... We received this error at the network level: Error: connect ECONNREFUSED 127.0.0.1:3000".

cypress
cy.visit() failed trying to load:

http://localhost:3000/

We received this error at the network level:
  > Error: connect ECONNREFUSED 127.0.0.1:3000

Common causes

The app server had not started yet

Cypress began before the dev/prod server bound its port, so the very first visit is refused.

baseUrl points at the wrong port or host

The configured baseUrl does not match where the app actually listens, so every visit is refused.

How to fix it

Wait for the server before running Cypress

Use wait-on (or the cypress-io GitHub Action's wait-on) so tests start only after the URL responds.

.github/workflows/ci.yml
- run: npm run start &
- run: npx wait-on http://localhost:3000
- run: npx cypress run

Set baseUrl to the real address

Point baseUrl at the exact host and port the app binds so visits resolve.

cypress.config.js
module.exports = defineConfig({
  e2e: { baseUrl: 'http://localhost:3000' },
});

How to prevent it

  • Gate Cypress on a wait-on / health check for the server URL.
  • Keep baseUrl aligned with the server's bind address.
  • Start the server in the same job and confirm it is up before testing.

Frequently asked questions

What causes ""cy.visit() failed trying to load""?
Cypress began before the dev/prod server bound its port, so the very first visit is refused.
How do I fix "cy.visit() failed trying to load"?
Use wait-on (or the cypress-io GitHub Action's wait-on) so tests start only after the URL responds.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card