Next.js Discord

Discord Forum

Fetch failed error

Answered
American Pipit posted this in #help-forum
Open in Discord
American PipitOP
component:
    const message = await fetch('localhost:3000/api/employers/route.ts');

    return (
        <>
            <Navbar user={user} />
            <EmployerContent employers={employers} />
            <p>{message?.json()}</p>
        </>
    );

route:
export async function GET() {
    return NextResponse.json({ message: 'Hello World!' });
}


I get a Unhandled Runtime Error Error: fetch failed
Answered by riský
you can use [unstable_cache](https://nextjs.org/docs/app/building-your-application/caching#unstable_cache) to have the same cache as fetch
View full answer

5 Replies

@riský https://nextjs-faq.com/fetch-api-in-rsc
American PipitOP
I wanted to do fetch(path, {tag: ''}) so I can revalidate the tag. How can I create/revalidate a tag if I'm using supabase API directly in the component?
you can use [unstable_cache](https://nextjs.org/docs/app/building-your-application/caching#unstable_cache) to have the same cache as fetch
Answer
@riský https://nextjs-faq.com/fetch-api-in-rsc
Pink salmon
thnaks
@American Pipitdo you have any more questions (ie was the unstable_cache recommendation good enough)