https://cypress.io logo
Cannot connect to local host on browser instance r...
# i-need-help
a
Hi, newbie here. So I cannot connect to my local host, using
Copy code
ts
cy.vist('http://localhost:4200')
and the worst part: I cannot connect to http://localhost:4200 on a seperate tab in the browser instance that is running cypress. for an example. if I choose chrome as the browser, the test will not run, I will get the error
Copy code
ts
CypressError
cy.visit() failed trying to load:

http://localhost:4200/login

We attempted to make an http request to this URL but the request failed without a response.

We received this error at the network level:

  > Error: connect ECONNREFUSED 127.0.0.1:4200
and if on the same browser instance I create a new tab and go to http://localhost:4200, I do not get a response. same thing when I create a new window from that instance. But if I just open another browser instance that is not created by or from the instance running cypress, I can connect to local host and get the appropriate responses. Here is a link[https://drive.google.com/file/d/1exDHylkA8283rw2EUmHKEsczLsENzEm4/view?usp=sharing] of a video showing the issue. I used different browsers to test and same result.
I have looked it up a bit more, seems like cypress converts localhost:4200 to its ipv4 address and port 127.0.0.1:4200, and if I open any browser and try to go to the ipv4 address, it fails to connect. I am not sure if this could be the reason why, but it def could be it.
Update: I opted to use the ipv6 address
[::1]:4200/login
on the browser instance running cypress and it connects. but cypress is now picking the absolute path of my project folder and appending the ip address at the end:
Copy code
sh
cy.visit() failed trying to load:

http:://[::1]:4200/login

We failed looking for this file at the path:

/Users/username/path/to/project/root:/[::1]:4200/login
m
Hi @agreeable-lunch-15323 This is a problem with some of the servers. Which one are you using? Some of them can be started in a different way which allows them to listen on IPv4 and IPv6.
a
I am using firebase, let me pull up the server information.
I am runnning a nestJs server
node v18.16.0
m
Node.js 17 and later have changes which make this problem appear. Node.js 16 doesn't have the issue.
a
cool. I will downgrade.
will give feedback just now
Happy to say that after not sleeping the whole night, you have helped me resolve this. I failed to find similar issues on the internet. So I appreciate this a lot.
m
Great to hear that the workaround is good for you! Are you running your tests locally or on a remote system like GitHub runner? I have only seen this issue on remote systems but it depends exactly how the network is set up.
a
Nah I am running it locally. Which I think it is not good think?
m
It's no problem to run it locally if that is what you need and what works for you!
a
cool thank you for your help, it all ran well, produced videos and tests passed.
m
Very nice to hear about your success!
3 Views