Receiving ECONNREFUSED when using graphql and next.js

@sambrockway Do you know if there is a port or something that my machine could be blocking? Do you know what channel it uses to make the connection?
Thanks!

Can you try downgrading to version 6.5.2 here: Releases - Local

There may be a conflict with Electron and Next.js’ Image component, and some of those error reports are similar to yours @hamlethub

I downgraded, and still receive the error. I did not completely uninstall version 6.6, but Local says I am running version 6.5.2.

I have not connected it to the Next.js frontend yet. I receive the error after a clean install, and then just opening the site.

Is it normal that the node.js host is different from Wordpress address?
Node.js host from Local dashboard - localhost:10007
from local.env file - NEXT_PUBLIC_WORDPRESS_URL=http://localhost:10005
wp Admin address (works) - http://localhost:10005/wp-admin/

If it helps, this person had the exact error with version 6.5.2 - http://community.localwp.com/t/bad-port-error-with-new-site-created-with-atlas-add-on/34513

Below is the output - It believes the port is out of range.


> @faustjs/next-headless-getting-started@0.1.0 dev
> next dev -p $PORT

RangeError [ERR_SOCKET_BAD_PORT]: options.port should be >= 0 and < 65536. Received NaN.
    at new NodeError (node:internal/errors:372:5)
    at validatePort (node:internal/validators:217:11)
    at Server.listen (node:net:1500:5)
    at C:\Users\kendu\Local Sites\hsatlas\app-node\node_modules\next\dist\server\lib\start-server.js:55:16
    at new Promise (<anonymous>)
    at Object.startServer (C:\Users\kendu\Local Sites\hsatlas\app-node\node_modules\next\dist\server\lib\start-server.js:22:12)
    at nextDev (C:\Users\kendu\Local Sites\hsatlas\app-node\node_modules\next\dist\cli\next-dev.js:129:23)
    at C:\Users\kendu\Local Sites\hsatlas\app-node\node_modules\next\dist\bin\next:147:44 {
  code: 'ERR_SOCKET_BAD_PORT'
}

Thanks for trying the downgrade option. Just to confirm that this latest failure was with the Atlas add-on. It is normal that the headless site and WP install would have different addresses. With 6.5.2 installed can you try running either the Vercel starter or the one from our tutorial to confirm that you get the same error? Thanks again for hanging in there. I’ll see what I can do to get more eyes on this

yes, the failure was with Atlas add-on.

Unlike the initial try with graphql, this time I simply added a Local site with the atlas add-on, and went to the ā€œopen siteā€, and received a 502 error. The WP admin site works fine. If I add a site without the Atlas add-on it works fine.

Do I need to have it attached to a next.js site for the local URL to work?

Could it be something with the way I have node installed?

Thanks,

Ken

@JeffEverhart383 I believe this has something to do with node, but can’t figure out what could be different about my setup.

@hamlethub have you tried a different version of node using nvm? GitHub - nvm-sh/nvm: Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

That could be worth a try. Maybe try node v16.

And it looks like you’re using a Windows machine here, which I know nothing about. Are there different shells you can use?

But I’m puzzled b/c I’d still expect the blueprint from the Atlas add-on to just work.

I can try different shells. However, Atlas will not let me open the front end, even before I start the front end using Next.js/npm. Directly from Local, selecting ā€œopen siteā€ gives me a 502 error. The admin site works fine though.

Is there an alternative to Atlas/Graphql? If I can get this to work another way, maybe that would help us to narrow this down.

Yeah, the alternative to using the GraphQL API would be to just use the default REST API. If you could go back to just using a Local WP site for the backend and then either the Vercel starter or our starter and make a fetch request to the REST API, I guess that would give us additional info.

I was able to solve this with the help of Moazam (https://www.codementor.io/@moazam) He determined that my node.js was ā€œjailedā€. I reinstalled node.js with a different shell, and ran ā€œnpm run devā€ under that shell.

In addition, I had to take the ā€œ/graphqlā€ out of the endpoint in .env.local. Therefore the statement in .env.local is: ā€œNEXT_PUBLIC_WORDPRESS_API_URL=http://localhost:10044ā€. Not sure why, but in case it helps someone.

The admin backend will load, the next.js site will connect and show posts, but the Wordpress frontend will not load. I am not concerned about that because I will not be using it but FYI.

Thanks for your help!

Ken

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.