#Need Help 📍Type Error: Fetch Failed

21 messages · Page 1 of 1 (latest)

twilit topaz
#

Everything was going well but today I made a commit updating to 2.7.0 in my backend, and the storefront deployment has failed. For some reason, I’m getting a “fetch failed” error, and sometimes it doesn’t even get that far — it just hangs on “await backend to be available.” I’ve spent several hours on this but I can’t figure out why. The AI suggests it might have something to do with the .env files, but I haven’t touched anything at all. From yesterday to today I’ve only changed the backend and nothing related to the .env. Any suggestions on what it could be? Thank you very much for your time. Here’s the error.

It all starts when the static pages are generated — at that point, it enters a loop that can last more than 20 minutes where every fetch fails. It’s as if the backend were down, but it’s not. And I’ve double-checked all the .env files — they’re correct.

Generating static pages (197/790)

TypeError: fetch failed
at node:internal/deps/undici/undici:13392:13
at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
digest: '3433511878',
[cause]: Error: Client network socket disconnected before secure TLS connection was established
at TLSSocket.onConnectEnd (node:_tls_wrap:1732:19)
at TLSSocket.emit (node:events:530:35)
at endReadableNT (node:internal/streams/readable:1698:12)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
code: 'ECONNRESET',
path: undefined,
host: 'backend-production-b057.up.railway.app',
port: 443,
localAddress: null
}
}

twilit topaz
kind anchor
#

Hey.

Your .env files are not being used on Railway. There, your environment variables comes from Railways build system, and are managed in the dashbaord for each of your services. You did not change anyther here I assume?

Let me ask you, how did you update to 2.7.0 ?

And did you check the runtime logs for the backend? Despite being online, something might be broken if dependencies are not updated correctly.

twilit topaz
#

I haven’t touched the .env files.
I updated the version to 2.7.0 in 4 dependencies in the package.json: Medusa, framework, CLI, and admin.
Then I deleted the pnpm-lock.yaml file and ran pnpm install.
Also, looking at the backend HTTP logs, I'm getting a huge number of GET requests from the storefront that I didn’t trigger.

twilit topaz
#

It can stay like 30 minutes trying to build image, trying to fetch all the time.

kind anchor
#

Hmm. That sounds odd. 🤔 is your git repo public? Can I see it ?

twilit topaz
#

Yeah sure https://github.com/alejandro-myurban/medusajs-2.0-for-railway-boilerplate-FwVm I've been thinking, yesterday was fine. Today I did update to 2.7.0 and commited. Backend and admin dashboard working fine but storefront deploy started to fail like this. I think it must be the update, i fucked it up or something i dont know but i didnt touch a single letter on storefront so...

GitHub

Contribute to alejandro-myurban/medusajs-2.0-for-railway-boilerplate-FwVm development by creating an account on GitHub.

kind anchor
#

I see that you have updated dependencie in the storefront - I generally don't recommend doing that without caution, the storefront is notoriously difficult to update, and very "fragile". I have spent 10s of hours trying to update it in the past. For now, I need to have a REALLY good reason to update anything in the storefront before I would attempt it.

And I can see that you have quite a lot of commits, more that I can spend time going through one by one unfortunately. So I would suggest that you revert to an earlier commit where your setup was building without error.

And see that it again builds successfully.

From here, I would consider what to update and why. The backend is usually easy to update, but I can't say the same about the storefront 🙂 I hope this helps....

twilit topaz
#

thank you! yes i did that, i put my head commit 2 days ago, and somehow still same error. Im really sad XDD

kind anchor
#

Okay I have one suggestion for you. You could try to run migrations against the database.
Get the **public **database url from your Railway postgres database (DATABASE_URL), and add it to you backend .env file (locally)

This will connect your local project to your production database - so be careful, remember to remove this line again (or comment out)

Open terminal inside /backend and run the command: npx medusa db:migrate this shuold migrate your production databse to match your core dependencies.

Then try to rebuild your project on Railway and see if there's any progress

#

If this does not work either.. One thing that you can try to see if the issue roots in your storefront or your backend, would be to create one more instance of the storefront but connected to the boilerplate repo, not your own. It's a little hard for me to explain all the steps, but I will be happy to help you with it, if you invite me to your Railway project. But first try the migration mentioned above 😉

twilit topaz
#

I did that, and migrate. And not even in railway, when i locally try to npm run build, starts to break again. In the moment it wants to generate static pages, a hundreds of gets start coming to the backend. A lof of them failed. Its really really weird. Its like there's a mismatch or storefront cant reach backend 100% since almost all static pages are collected but not all of them.

#

If you clone the project and start backend, and try to npm run build the storefront, you will see the whole thing there

#

I can provide you with the .env and stuff i dont know what to do anymore haha

kind anchor
#

i'll clone your repo and see if it get same errors

kind anchor
#

Hmm. that's strange... I had no problem running your project 😬 You can see the build log attached...

First I installed dependencies in backend cd backend pnpm i
Then I initialised the backend pnpm ib (seeds the database becasue my local database is empty)
Then i installed dependencies in storefront cd storefront pnpm i
The I run the backend pnpm dev
Then I build the storefron pnpm build

I use pnpm, and I see you are using npm - but this should make ay difference..

#

For environment variables I used:

/backend/.env

NODE_ENV=development
# REDIS_URL=redis://localhost:6379 # Optional - falls back to simulated redis
ADMIN_CORS=http://localhost:7000,http://localhost:7001,https://docs.medusajs.com
STORE_CORS=http://localhost:8000,https://docs.medusajs.com
AUTH_CORS=http://localhost:7000,http://localhost:7001,https://docs.medusajs.com
JWT_SECRET=supersecret
COOKIE_SECRET=supersecret
DATABASE_URL=postgres://postgres:postgres@localhost:5432/medusa-ale# Make sure this database exist - or change connection string to an online database

MEDUSA_ADMIN_EMAIL=admin@yourmail.com
MEDUSA_ADMIN_PASSWORD=supersecret

STRIPE_API_KEY=
STRIPE_WEBHOOK_SECRET=

SENDGRID_API_KEY=
SENDGRID_FROM=
#

/storefront/.env.local

# Your Medusa backend, should be updated to where you are hosting your server. Remember to update CORS settings for your server.
NEXT_PUBLIC_MEDUSA_BACKEND_URL=http://localhost:9000

# Your store URL, should be updated to where you are hosting your storefront.
NEXT_PUBLIC_BASE_URL=http://localhost:8000

# Your preferred default region. When middleware cannot determine the user region from the request IP, this will be used instead.
NEXT_PUBLIC_DEFAULT_REGION=us

# Minio endpoint for image storage (optional)
# NEXT_PUBLIC_MINIO_ENDPOINT=bucket-production-eaeb.up.railway.app

# MeiliSearch Configuration
# The URL of your MeiliSearch instance (default: http://localhost:7700 or auto-configured on Railway)
NEXT_PUBLIC_SEARCH_ENDPOINT=http://localhost:7700

# Your MeiliSearch search key (auto-configured on Railway)
NEXT_PUBLIC_SEARCH_API_KEY=your_search_key_here

# The name of the index in MeiliSearch (matches backend configuration)
NEXT_PUBLIC_INDEX_NAME=products

The only difference I can think of, is that my database is seeded with fresh demo data, and you probably have some configurationds and products etc. in your database.

Additionally, I am probably using some other .env value than you?

Other than that, I can't see what should be different 🤔 I use node v. 18.20.4

dusky fable
#

probably due to cors

kind anchor
#

That sounds like a very plausible theory, that would prevent the backend and storefront from communicating