Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn when localhost is not mapped to 127.0.0.1 and launch Cypress directly on that ip address #1630

Open
brian-mann opened this issue Apr 22, 2018 · 8 comments
Labels
type: feature New feature that does not currently exist type: unexpected behavior User expected result, but got another

Comments

@brian-mann
Copy link
Member

When users /etc/hosts file is nuked or has had the localhost -> 127.0.0.1 ip address mapping removed then Cypress will fail to spawn the browser correctly.

We can detect this and provide a warning to the user, and additionally could just launch the browser on 127.0.0.1 as opposed to localhost.

Related to: #1455 and #680

@brian-mann brian-mann added type: feature New feature that does not currently exist type: unexpected behavior User expected result, but got another labels Apr 22, 2018
@brian-mann brian-mann self-assigned this Apr 22, 2018
@punkosu
Copy link

punkosu commented May 29, 2019

I just ran into this, and spent a little bit of time debugging to figure it out. A warning message would be a nice to have

@brian-mann
Copy link
Member Author

brian-mann commented May 29, 2019

@flotwig hey see I'm not crazy it does happen. Maybe we can fix this - it should be fairly simple - but there may be a lot of hard coded localhost strings everywhere that we'd have to synchronize and update.

We likely need to pass around a defaultHostname configuration variable and then point to that everywhere - and let the server initially set this if baseUrl is not specified by testing to see that localhost is mapped to 127.0.0.1.

@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label May 30, 2019
@flotwig
Copy link
Contributor

flotwig commented May 30, 2019

Logging a warning if localhost !== 127.0.0.1 would be nice, as we do make that assumption in a lot of places. So would launching the test runner on 127.0.0.1 instead of localhost.

@khan-zia
Copy link

khan-zia commented Feb 21, 2022

It's been 4 years, I ran into a similar issue today. @jennifer-shehane @brian-mann

@cypress-bot cypress-bot bot added stage: backlog and removed stage: ready for work The issue is reproducible and in scope labels Apr 29, 2022
@pm0u
Copy link

pm0u commented Oct 5, 2023

What is the fix for this? Everything in my org uses http-get://localhost:3333 to initiate cypress so I can't modify the URL... but it only works if I change the CLI params to http-get://127.0.0.1:3333

This is on MacOS Ventura

@MikeMcC399
Copy link
Contributor

@pm0u

You may be running into a issue where your dev server is not responding on both IPv4 and IPv6 stacks. This is something which can be a problem with Node.js 18 and 20.

Depending on the network setup localhost may map to the IPv4 loopback address 127.0.0.1 or to the IPv6 loopback address ::1 or both.

You may want to open a separate issue so that you can provide full details, including which dev server you are using. There is a recent related issue where I gave some comments

@pm0u
Copy link

pm0u commented Oct 9, 2023

Thanks @MikeMcC399 - not sure if this is the "best" fix but I did manage to get this working by commenting out the IPv6 localhost loopback that was in my hosts file

#::1 localhost

that line was last and previously not commented. We are running Node 18.16, maybe node found that IPv6 was available as a loopback and ignored the ipv4 binding? Not sure - it was particularly confusing as localhost worked in all browsers but maybe theres more magic in those environments to manage ipv4/6. I'll leave this here in case others run into the issue but if I am still having problems I'll make a new issue to track my particular case.

@MikeMcC399
Copy link
Contributor

@pm0u

Good to hear that you've got things working! I wouldn't worry too much about whether this is the best workaround. There isn't a one-size-fits-all solution and if your workaround is doing the job, then just stick with it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature New feature that does not currently exist type: unexpected behavior User expected result, but got another
Projects
None yet
Development

No branches or pull requests

7 participants