TypeError: fetch failed error without much description in the logs
Full error below:
TypeError: fetch failed
at Object.fetch (/app/node_modules/next/dist/compiled/undici/index.js:1:26669)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async invokeRequest (/app/node_modules/next/dist/server/lib/server-ipc/invoke-request.js:17:12)
at async invokeRender (/app/node_modules/next/dist/server/lib/router-server.js:254:29)
at async handleRequest (/app/node_modules/next/dist/server/lib/router-server.js:447:24)
at async requestHandler (/app/node_modules/next/dist/server/lib/router-server.js:464:13)
at async Server.<anonymous> (/app/node_modules/next/dist/server/lib/start-server.js:117:13) {
cause: Error: connect ECONNREFUSED 127.0.0.1:36959
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1278:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 36959
}
}
Same code works fine on Vercel with no exceptions. Using NextJS 13 with Supabse. Error happens on home page without much if any complex functionality, just some text, couple images and a nav bar. One of the images doesn't display even though it's in the package.
Project ID is 592b7020-b78a-45d7-96f2-414c4a4c7757/
23 Replies
Project ID:
592b7020-b78a-45d7-96f2-414c4a4c7757
what are you trying to connect to at 127.0.0.1
Actually nowhere, I have no connections to that address anywhere in the code. It's something Railway is trying to do, and I'm not sure what.
railway runs your code as is, it will not make connection attempts on your behalf
I'm pretty sure it's trying to load an image and failing. I deployed same codebase to Vercel and there are no isses in logs and both images are being displayed while with Railway only one image is displayed and there's this error.
are you perhaps trying to connect to supabase without supplying any credentials and your code is falling back to trying to connect to 127.0.0.1?
So, Supabase seems to be causing another issue actually. I have the following code on the main page:
const supabase = createServerComponentClient({ cookies })
const {
data: { user },
} = await supabase.auth.getUser()
Then there's verification if there's user and different behaviour based on that.
Interestingly, when I login/signup with Supabase both locally and on Vercel redirects work as expected while at Railway it tries to send me to localhost to some strange port
railway runs your code as is, if the service on railway is redirecting you to localhost it's because that's what your code is doing, if your service on vercel is not redirecting you to localhost, it's because vercel is monkeypatching your code for you
https://docs.railway.app/develop/variables#railway-provided-variables
you can use the
RAILWAY_PUBLIC_DOMAIN
environment variable to setup the redirect location properlyOh this might be what I was missing, let me try that!
have you also added the supabase credentials to the service variables?
yeah I have. It reads and writes data from supabase just fine
Adding a variable didn't seem to help, and again - images aren't being displayed. Does Railway support the new Next 13 folder structure?
again, railway runs your code as is
the only issue i could see would be this being an issue with node 16 since node 16 is the default version used
try setting
engines.node
to 18
in your package.jsonoh this seems to have fixed it
image is loading now and that error is no longer in the log
Still weird redirect to a locahost when after logging in / signing out with supabase, gotta figure that one out.
Even locally, it doesn't redirrect me to a strange localhost port, it keeps it within whatever port I'm on
seems like you haven't setup the callback url properly, then next is trying to redirect you to whatever random port next is running on
maybe you are missing this?
NEXTAUTH_URL=https://${{RAILWAY_PUBLIC_DOMAIN}}
I'm not using next auth but using supabase auth instead.
fair, was just a guess to set you in the right direction
yeah, no, I definitely appreciate it
you just gotta find a way to set the callback url
I may need to talk with them maybe. It works locally and on Vercel, but I wonder if Vercel is indeed doing some monkey business like you said, and I'm just missing something. I took the code straight from Supabase template so theoretically it should work, maybe I am indeed missing something simple
who is "them" lol
Supabase π
read supabase's docs
will do, thank you for your help!