Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

3.3K
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!