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

Next.js server start hangs #348

Closed
eyaleizenberg opened this issue Jan 3, 2023 · 14 comments · Fixed by #357
Closed

Next.js server start hangs #348

eyaleizenberg opened this issue Jan 3, 2023 · 14 comments · Fixed by #357
Labels

Comments

@eyaleizenberg
Copy link

I created a new next.js project and added start-server-and-test but no matter what I do, the test run doesn't start. This is my output:

start-server-and-test http-get://localhost:3000 cypress.run

1: starting server using command "npm run start"
and when url "[ 'http-get://localhost:3000' ]" is responding with HTTP status code NaN
running tests using command "npm run cypress.run"


> rhino-next@0.1.0 start
> next start

ready - started server on 0.0.0.0:3000, url: http://localhost:3000

I ran the curl command to check if a Head request returns 200 and it does.

curl --head http://localhost:3000/     
HTTP/1.1 200 OK
X-Powered-By: Next.js
ETag: "dz0spzxup038i"
Content-Type: text/html; charset=utf-8
Content-Length: 4199
Vary: Accept-Encoding
Date: Tue, 03 Jan 2023 08:12:49 GMT
Connection: keep-alive
Keep-Alive: timeout=5

My guess is the part the says is responding with HTTP status code NaN is the problem.

What am I missing here?

Thanks.

@tvsbrent
Copy link

tvsbrent commented Jan 5, 2023

I am seeing this problem as well. I'm using http-server for hosting my test site in this case.

EDIT: Looks like in version 1.15.0 an --expect argument was added, so now you need to have something like --expect 200 to your command. In my case, adding that argument removed the NaN from the logging, replacing it with a 200, but so far as I can tell it didn't seem to progress to running the tests.

EDIT 2: After fiddling a bit more, I came up with this update to the command in the package.json:

-start-server-and-test 'http-server ./app --port=8082' 8082 'cypress run --e2e'
+start-server-and-test --expect 200 'http-server ./app --port=8082' http://127.0.0.1:8082 'cypress run --e2e'

The significant changes were:

  • I had to add the --expect 200 argument.
  • I had to change the old 8082, which told the command the port, to http://127.0.0.1:8082.

This seemed to do the trick.

@dariobarrio
Copy link

dariobarrio commented Jan 9, 2023

I had the exactly same problem (in local) that what @eyaleizenberg was reporting.

I downgrade from Node v18.13.0 to v16.19.0 and it works well again. Something there is not quite right.

@dkonasov
Copy link

Faced this issue as well. I was launching my tests with command

start-server-and-test 'npx http-server ./storybook-build -s -c-1 -p 8080' http://localhost:8080 'jest --config ./jest.e2e.config.js'

and my test haven't started. For me issue was resolved when I changed localhost to 127.0.0.1:

start-server-and-test 'npx http-server ./storybook-build -s -c-1 -p 8080' http://127.0.0.1:8080 'jest --config ./jest.e2e.config.js'

However, when I tried to connect to my storybook app on http://localhost:8080 during the first run, everything was fine, site was available by domain name.

My node version is 18.12.0, start-server-and-test version is 1.15.2

@mikansc
Copy link

mikansc commented Jan 17, 2023

A workaround that worked for me is to using the local IP address instead localhost on the starting script:

"ci": "start-server-and-test build-and-serve http://127.0.0.1:5000 cy:open"

See:
#333 (comment)
jeffbski/wait-on#109 (comment)

@MikeMcC399
Copy link

@mihailgaberov
Copy link

I had the same problem in a Meteor.js app. I fixed it by adding --expect 200 and passing explicitly the port that is used by Cypress UI to the server. The --expect param replaces NaN with 200, but without passing the port number the Cypress UI doesn't start at all.

Here is part of my package.json:

"start:e2e": "set METEOR_LOCAL_DIR=.meteor/test && meteor --port 4000",
"test:e2e": "start-test --expect 200 start:e2e :4000 cypress:ui"

@bahmutov
Copy link
Owner

Can someone please provide a small repo with a reproducible example?

@MikeMcC399
Copy link

@mihailgaberov

The --expect param replaces NaN with 200,

This issue is solved in v1.15.4.

@MikeMcC399
Copy link

  • I expect this is the same root cause as example-wait-on fails on GitHub waiting for localhost cypress-io/github-action#802 if the issue generally happens on GitHub running the default version of Node.js (currently 18.14.1). Judging by the other issue, running locally on any Node.js version there is no problem. On GitHub running Node.js 16 and earlier there is also no problem.

  • Next.js uses react and the react server only listens on the IPv4 address 127.0.0.1 however due to changes in Node.js >= 17 the dns lookup returns the IPv6 address ::1 on GitHub, so the wait-on test is trying on ::1 and react is waiting on 127.0.0.1. The two never meet up.

@MikeMcC399
Copy link

MikeMcC399 commented Feb 23, 2023

Which version of Next.js is causing an issue?

I set up a repository with Next.js 13 and latest versions of everything else and there was no issue with start-server-and-test. When I run npm run dev locally the server responds to http://localhost:3000, http://127.0.0.1:3000 (IPv4) and http://[::1]:3000 (IPv6). In problematic configurations with other products I found that the servers do not respond to both IPv4 and IPv6.

@MikeMcC399
Copy link

I suggest to open a separate issues for each other server that has been mentioned here, that is ones which are not Next.js, otherwise troubleshooting in this issue is going to get quite confusing!

@eyaleizenberg Are you still having an issue with Next.js?

@bahmutov
Copy link
Owner

Can someone provide a repo with an example that shows the problem? Or debug logs? Anything?

@MikeMcC399
Copy link

@bahmutov

Can someone provide a repo with an example that shows the problem? Or debug logs? Anything?

sabertazimi added a commit to sabertazimi/blog that referenced this issue Feb 25, 2023
sabertazimi added a commit to sabertazimi/blog that referenced this issue Feb 25, 2023
* ci(node): switch to Node.js v18

* ci(scripts): change localhost ip

issue bahmutov/start-server-and-test#348
@github-actions
Copy link

🎉 This issue has been resolved in version 1.15.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
8 participants