Next.js Discord

Discord Forum

TypeError: fetch failed only in production build, but works in local

Unanswered
Bigheaded ant posted this in #help-forum
Open in Discord
Avatar
Bigheaded antOP
I'm building a site with NextJS that uses Strapi for the content, I'm self hosting both in a Coolify instance and i na VPS. So when developing the site locally I use the public strapi url and works just perfectly, but then into the production build site and after navigating into a page with parameters (which is just the page id to fetch individual data) throws this TypeError: fetch failed and I've been struggling to find the solution
TypeError: fetch failed
    at node:internal/deps/undici/undici:12618:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async p (/app/.next/server/app/proyectos/[slug]/page.js:1:14879) {
  cause: ConnectTimeoutError: Connect Timeout Error
      at onConnectTimeout (node:internal/deps/undici/undici:7760:28)
      at node:internal/deps/undici/undici:7716:50
      at Immediate._onImmediate (node:internal/deps/undici/undici:7748:13)
      at process.processImmediate (node:internal/timers:476:21)
      at process.callbackTrampoline (node:internal/async_hooks:128:17) {
    code: 'UND_ERR_CONNECT_TIMEOUT'
  },
  digest: '302496454'
}

And this is my code that's generating the issue
import { notFound } from "next/navigation";

export default async function Proyectos({params}) {

  const query = await fetch(`${process.env.STRAPI_URL}/api/proyectos?filters[slug][$eq]=${params.slug}&populate=*`);

  const response = await query.json();
  const proyecto = response.data[0];
  if(!query.ok||!proyecto){
    notFound()
  }

  return (<>
  {proyecto.name}  
  </>
)

}

I've already verified that the .env variable is properly set, that the endpoint has no cors issues and that the "params" is not null. What weirdens me the most is that I have another call to that same api (another route, just /api/proyectos) works just fine, and that call is at app/page.tsx
What else should I try? thanks in advance!

1 Reply

Avatar
Bigheaded antOP
any suggestions? i forgot to mention I'm using next 14.2