Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

3.3K
Vistas
Unhandled Runtime Error Error: Failed to fetch+ SWR+NEXT JS

I have migrated my app from react 17.02 to use the latest version. recently from here.

I am trying to use /api routes to fetch data at client side using SWR.

lib/fetch

export default async function fetcher(...args) {
  const res = await fetch(...args);
  if (!res.ok) throw new Error('Failed to fetch');
  return res.json();
}

This is inside in /pages/dashboard:

  const { data, error } = useSWR(process.env.APP_URL + '/api/user', fetcher, { suspense: true });

  const router = useRouter();

  useEffect(() => {
    setUser(data);
    console.log(series);
  }, [data, user]);
  if (error) {
    router.push('/404');
  }
 return (
    <Suspense fallback={<div>Loading...</div>}>
      <div className="h-screen max-w-7xl mx-auto px-4 bg-background-dark">
        <Header title="Dashboard" />
        <h1 className="text-5xl text-white">You will see all the series here</h1>
      </div>
    </Suspense>
  );

env.local

APP_URL=http://localhost:3000

The application tries to go to this url.

http://localhost:3000/undefined/api/user

runtime_error

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda