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

New NX project - NextJS connect ECONNREFUSED 127.0.0.1:4200 #17902

Closed
1 of 4 tasks
binaryartifex opened this issue Jul 1, 2023 · 24 comments
Closed
1 of 4 tasks

New NX project - NextJS connect ECONNREFUSED 127.0.0.1:4200 #17902

binaryartifex opened this issue Jul 1, 2023 · 24 comments
Assignees
Labels
blocked: retry with latest Retry with latest release or head. outdated scope: nextjs Issues related to NextJS support for Nx type: bug

Comments

@binaryartifex
Copy link

Current Behavior

My nextjs applications are no longer being served locally. While waiting for the initial build to view application locally in the browser, after a minute or two I am presented with a "connect ECONNREFUSED" error.

Expected Behavior

To view my application locally without interruption.

GitHub Repo

No response

Steps to Reproduce

  1. pnpm dlx create-nx-workspace --packageManager="pnpm"
    1a. React Stack -> NextJs Framework -> Integrated Monorepo -> Yes to App Router -> CSS Stylesheets -> No to cache
  2. Start application, wait several minutes. It will either not appear at all with an eventual ECONNREFUSED error, or it will appear for a few minutes before crashing with the same error.

Nx Report

Node   : 18.15.0
   OS     : win32-x64
   pnpm   : 8.6.2
   
   nx                 : 16.4.2
   @nx/js             : 16.4.2
   @nx/jest           : 16.4.2
   @nx/linter         : 16.4.2
   @nx/workspace      : 16.4.2
   @nx/cypress        : 16.4.2
   @nx/devkit         : 16.4.2
   @nx/eslint-plugin  : 16.4.2
   @nx/next           : 16.4.2
   @nx/react          : 16.4.2
   @nrwl/tao          : 16.4.2
   @nx/web            : 16.4.2
   typescript         : 5.1.6

Failure Logs

> nx run public-website:serve:development

- ready started server on localhost:4200, url: http://localhost:4200
- event compiled client and server successfully in 2s (311 modules)
- wait compiling...
- event compiled client and server successfully in 1104 ms (311 modules)
node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^
Error: connect ECONNREFUSED 127.0.0.1:4200
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
  errno: -4078,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 4200
}
Node.js v18.15.0

Operating System

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

Additional Information

Updating the next package to the latest one doesn't help either. I suspect the issue lies with NX and not NextJS because after creating an initial application with just nextjs without the use of NX, it appears to works just fine.

@binaryartifex
Copy link
Author

tried updating to the latest 16.5.0-beta.0 with my production workspace and it still occurs. only this time it will build and serve locally, however in less than 2 minutes it disconnects with the same error.

@rahulretnan
Copy link

Facing the same issue, does this have anything to do with this merge #17856 ?

@rahulretnan
Copy link

I solved the issue by adding, hostname value as 0.0.0.0 in the project.json

"serve": {
      "executor": "@nx/next:server",
      "defaultConfiguration": "development",
      "options": {
        "buildTarget": "myapp:build",
        "dev": true
      },
      "configurations": {
        "development": {
          "buildTarget": "myapp:build:development",
          "dev": true,
          "hostname": "0.0.0.0"
        },
        "production": {
          "buildTarget": "myapp:build:production",
          "dev": false
        }
      }
    }

@Brian-McBride
Copy link

I just learned that NextJS doesn't even use the React version you install in your NPM lib when using the app directory. Next is the current lovechild of the front-end community, but that lib seriously breaks a lot of expected conventions.

It seems that this hostname fix is more of a hack? It would nice to know what the real issue is under the hood. The last couple NextJS updates have also caused my project to run out of memory every 30m or so (in dev mode)

@charleskoehl
Copy link

charleskoehl commented Jul 2, 2023

This started happening to me after upgrading from 16.4.0 to nx 16.4.2

I run 4 next.js apps locally for dev, all with "nx serve"

I also noticed a huge difference in the memory usage of each node process involved:

  • In 16.4.0, each node process remains between 724 MB and 1005 MB.
  • In 16.4.2, each node process keeps growing until they get over 4400MB and cause my Mac to run out of RAM.

@ubirajaramneto
Copy link

I am facing the same issue.

Upgraded from 16.3.2 to 16.4.2 and now I can not serve my next.js application locally anymore.

@MartinDavi
Copy link

MartinDavi commented Jul 3, 2023

Same issue here, went from 16.3.2 to 16.4.2 and cannot develop locally on mac:

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

@ajmalmsali
Copy link

Got the same issue

@kkeertipati
Copy link

📉 Downgrade Nx version

🔀 Command: nx migrate 16.3.2

@andersonba
Copy link

It might not be related, but I describe a similar memory resource issue here: #17395

@olegshilov
Copy link

Have same issue

@leosvelperez leosvelperez added the scope: nextjs Issues related to NextJS support for Nx label Jul 5, 2023
@michaelangeloio
Copy link

What version of Next is everyone using? These may be partially related:

I think the last one is the fix. Using node 16 works for me, but not node >16

@MartinDavi
Copy link

I was and still am on [email protected] and [email protected], before and after upgrading nx and reverting.

@ndcunningham
Copy link
Contributor

ndcunningham commented Jul 5, 2023

Can you upgrade to the latest version of Nx? We just published v16.5.0.

Initially, we thought that having the defaulted localhost as the hostname would be fine but there it's actually an issue with Node: nodejs/node#40537.
We reverted that change and that has been published

Here is a repo of a fresh app: https://github.com/ndcunningham/issue-17902

@ndcunningham ndcunningham self-assigned this Jul 5, 2023
@ndcunningham ndcunningham added the blocked: retry with latest Retry with latest release or head. label Jul 5, 2023
@michaelangeloio
Copy link

Can you upgrade to the latest version of Nx? We just publish v16.5.0.

Initially, we thought that having the defaulted localhost as the hostname would be fine but there it's actually an issue with Node: nodejs/node#40537. We reverted that change and that has been published

Here is a repo of a fresh app: https://github.com/ndcunningham/issue-17902

Can you reference the PR associated with the revert?

@charleskoehl
Copy link

I'm on [email protected] and node v18.14.1

@charleskoehl
Copy link

I upgraded to 16.5.0 and the problem is gone. node processes no longer keep growing.

@ndcunningham
Copy link
Contributor

ndcunningham commented Jul 6, 2023

Can you reference the PR associated with the revert?

Here is the PR for the revert: #17931

@podjames
Copy link

podjames commented Jul 6, 2023

I am still seeing the same issue even after upgrading to the latest nx version- we are on [email protected] and [email protected]. Falling back to [email protected] also doesn't seem to help. Node version is 18.16.1.

Reverting to using Node 16 seems to fix it.

@olegshilov
Copy link

olegshilov commented Jul 6, 2023

@podjames

I am still seeing the same issue even after upgrading to the latest nx version- we are on [email protected] and [email protected]. Falling back to [email protected] also doesn't seem to help. Node version is 18.16.1.

Reverting to using Node 16 seems to fix it.

You can try nx reset.
If it's doesn't not help, try to remove lockfile and reinstall dependencies
btw. We use latest NextJS and after update all works as expected

@podjames
Copy link

podjames commented Jul 7, 2023

@olegshilov

Thank you - I think we have found our issue now. We had the hostname in our Next.js project.json files set to 'localhost'. Removing this line from the project.json files seemed to fix the problem.

@ndcunningham
Copy link
Contributor

Closing as I think the issue has been fixed. Thanks!

@Paufdez30
Copy link

trigger en la promesa que se hace en js

@github-actions
Copy link

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 Aug 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked: retry with latest Retry with latest release or head. outdated scope: nextjs Issues related to NextJS support for Nx type: bug
Projects
None yet
Development

No branches or pull requests