Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

3.3K
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda