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

Cannot run Next.js app on localhost with nx serve #18120

Closed
1 of 4 tasks
tavvy opened this issue Jul 14, 2023 · 2 comments · Fixed by #18123
Closed
1 of 4 tasks

Cannot run Next.js app on localhost with nx serve #18120

tavvy opened this issue Jul 14, 2023 · 2 comments · Fixed by #18123
Labels
outdated scope: nextjs Issues related to NextJS support for Nx type: bug

Comments

@tavvy
Copy link
Contributor

tavvy commented Jul 14, 2023

Current Behavior

In production mode. When running a next.js app with a custom hostname (--hostname=localhost or set the option in project.json) then the process will eventually error after roughly 120s.

This is because the nx executor next:server is waiting for the server response on port 3000 and always 127.0.0.1.
https://github.com/nrwl/nx/blob/master/packages/next/src/executors/server/server.impl.ts#L85 because we are not forwarding the custom hostname. Next.js will not respond on localhost by default: vercel/next.js#51378 and so we will retry 120 times before exiting with an unhandled exception error.

node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^
Error: connect ECONNREFUSED 127.0.0.1:3000
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
  errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3000
}

This simple change would fix it:

await waitForPortOpen(port, { host: options.hostname });

Expected Behavior

I should be able to start my next application with the next:server executor on a custom hostname

GitHub Repo

No response

Steps to Reproduce

  1. Build basic next app
  2. nx serve --prod --hostname=localhost
  3. wait ~120s

Nx Report

Node   : 18.16.0
   OS     : darwin-arm64
   yarn   : 1.22.19
   
   nx (global)        : 16.0.3
   nx                 : 16.5.1
   @nx/js             : 16.5.1
   @nx/jest           : 16.5.1
   @nx/linter         : 16.5.1
   @nx/workspace      : 16.5.1
   @nx/cypress        : 16.5.1
   @nx/devkit         : 16.5.1
   @nx/eslint-plugin  : 16.5.1
   @nx/next           : 16.5.1
   @nx/node           : 16.5.1
   @nx/react          : 16.5.1
   @nrwl/tao          : 16.5.1
   @nx/web            : 16.5.1
   @nx/webpack        : 16.5.1
   nx-cloud           : 16.1.0
   typescript         : 5.1.3

Failure Logs

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@tavvy
Copy link
Contributor Author

tavvy commented Jul 14, 2023

#18123

@github-actions
Copy link

github-actions bot commented Sep 1, 2023

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: nextjs Issues related to NextJS support for Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants