R
Railway

✋|help

TypeError: fetch failed error without much description in the logs

Aandreyapopov9/8/2023
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/
Bbrody1929/8/2023
what are you trying to connect to at 127.0.0.1
Aandreyapopov9/8/2023
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.
Bbrody1929/8/2023
railway runs your code as is, it will not make connection attempts on your behalf
Aandreyapopov9/8/2023
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.
Bbrody1929/8/2023
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?
Aandreyapopov9/8/2023
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
Bbrody1929/8/2023
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 properly
Aandreyapopov9/8/2023
Oh this might be what I was missing, let me try that!
Bbrody1929/8/2023
have you also added the supabase credentials to the service variables?
Aandreyapopov9/8/2023
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?
Bbrody1929/8/2023
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.json
Aandreyapopov9/8/2023
oh 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
Bbrody1929/8/2023
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}}
Aandreyapopov9/8/2023
I'm not using next auth but using supabase auth instead.
Bbrody1929/8/2023
fair, was just a guess to set you in the right direction
Aandreyapopov9/8/2023
yeah, no, I definitely appreciate it
Bbrody1929/8/2023
you just gotta find a way to set the callback url
Aandreyapopov9/8/2023
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
Bbrody1929/8/2023
who is "them" lol
Aandreyapopov9/8/2023
Supabase 🙂
Bbrody1929/8/2023
read supabase's docs
Aandreyapopov9/8/2023
will do, thank you for your help!

Looking for more? Join the community!

Recommended Posts
Renamed user/organization for GitHub - unsafe?A student organization I work with has a cron job service for our database, and it's linked with ourContainer Failed to StartError Response from Daemonssh tunneling errorWhen trying to deploy a django project the following error occurs "raise ValueError('No password or Paths not working when deployed to railway but works in local environmentCurrently making a vite/typescript/react project that has working route handling locally but does nopgbouncerHey folks, I have a supabase and Nextjs (+ prisma) project deployed in Railway, what's the best optiAccessing files inside the volumewhat's the best way to export build artifacts from one service to another? during build process, a tHow usage-based resource management works ?Hello, how Railway manages resource scaling ? like how are vCPU and RAM scaled up and down automaticHow to dynamically scale the replicas of an APIs deployed via Railway based on demand?I have API service with a certain number of replicas, whats the recommended way to scale the number Laravel application failed to respondI am unsure what is causing the issue but the after deploying my laravel app, it still does not starRailway credits gone??I had $15.46 in credits, and now $5 is gone. I have a single project, and I know for a fact my projeInstalling apt packages for puppeteerHi, im trying to run puppeteer on Railway but am getting an error that it cant find some packages. IIs it possible to set permissions on volumes?Dockerfile is using user id of 1000,and the WORKDIR which they own is /app. A Volume is mounted at /Trying to pg_dump and getting this weird error:Hi guys I am following this tutorial: https://blog.railway.app/p/postgre-backup and i am getting thHow to check which region is the database in and how to request to change it (if needed)?We started on the hobby plan and now we are Pro plan. For GDPR compliance we need to check which regDjango projects loading issuesI have two Django projects that I have deployed and both projects are facing similar issues (most liClicking 'Observability' button goes to the wrong projectExpected Flow - You click on a project, go to 'Observability' and view the logs. - You then click onTell Nixpack to include public folder in buildI have an Axum build on Rust that is are web socket chat rooms, which also serves static files. When.NET 6.0 Deployment Failed during build processProject ID f8a04cde-c088-4000-923e-0de1e0d144aa I can not deploy my backend, this is the error NETSMonorepoIf I am inside monorepo how will assigning domain work I wanna asign domain in two aspectsI can not deploy angular project, killedI do not know what is the problem I hope someone can help me, Project ID dd70810d-29a4-4c5e-b7b4-f2