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

ECONNREFUSED with NextJS custom server #52215

Closed
1 task done
michaelangeloio opened this issue Jul 4, 2023 · 7 comments
Closed
1 task done

ECONNREFUSED with NextJS custom server #52215

michaelangeloio opened this issue Jul 4, 2023 · 7 comments
Labels
bug Issue was opened via the bug report template. locked

Comments

@michaelangeloio
Copy link
Contributor

michaelangeloio commented Jul 4, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.1.0: Sun Oct  9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.16.1
      npm: 9.5.1
      Yarn: N/A
      pnpm: N/A
    Relevant Packages:
      next: 13.4.9-canary.1
      eslint-config-next: 13.4.1
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.6
    Next.js Config:
      output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

https://github.com/vercel/next.js/blob/canary/examples/custom-server/server.ts

Link to the code that reproduces this issue or a replay of the bug

https://github.com/michaelangrivera/nextjs-bug

To Reproduce

git pull [email protected]:michaelangrivera/nextjs-bug.git
nvm use 18 (if nvm is installed)
npm ci
npm run nx serve next -- --configuration=local-with-server 

Describe the Bug

When trying to serve my application via a custom node server, I get the following error:

Error: connect ECONNREFUSED ::1:60982
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
  errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 60982
}

I understand the reproduction steps contain an NX monorepo; however, I think NX is unrelated. I think potentially related issues may be:

TLDR on how the repro repo works:

  • it compiles the custom server apps/next/server/main.ts (here)
  • compiles the next app files
  • runs the main.js output compiled from apps/next/server/main.ts

I'm not sure if setting the hostname to 127.0.0.1 is an actual fix since deploying to Fly.io would give me the following error:

WARNING The app is not listening on the expected address and will not be reachable by fly-proxy.
You can fix this by configuring your app to listen on the following addresses:
  - 0.0.0.0:8080
Found these processes inside the machine with open listening sockets:
  PROCESS             | ADDRESSES
----------------------*--------------------------------------
  /.fly/hallpass      | [fdaa:2:73eb:a7b:dc:c6a2:17b4:2]:22
  node server/main.js | 0.0.0.0:3000

Note: this does not occur with Node.js <17

I wonder if #51887 will solve the issue.

Expected Behavior

I should be able to run the custom server without issue locally and deploy it as a container.

If you install 13.4.1, you will see the app works.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

standalone, custom server

@michaelangeloio
Copy link
Contributor Author

Nevermind, I think the issue was that I was not passing hostname and port into the next function:

const nextApp = next({ dev, dir, hostname, port }) // <-- missing hostname, port

@michaelangeloio
Copy link
Contributor Author

I confirmed that was the issue. Apologies! Thank you!

@rathoddeepak
Copy link

rathoddeepak commented Jul 10, 2023

Thank you

worked for me also

@rathoddeepak
Copy link

add localhost as hostname

didn't work used 127.0.0.1 instead

@michal-markiewicz
Copy link

add localhost as hostname

didn't work used 127.0.0.1 instead

Thank you this worked for me

@antonioandrade
Copy link

Changing hostname from 0.0.0.0 to 127.0.0.1 worked in my scenario too.

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked
Projects
None yet
Development

No branches or pull requests

4 participants