Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

res.revalidate() is not a function in NextResponse of Nextjs for on-demand ISR

NextResponse does not have res.revalidate('/'). i'm using v12.2.5 but it is there from v12.2.0. i want to use on-demand ISR in typescript.

https://nextjs.org/blog/next-12-2#on-demand-incremental-static-regeneration-stable

export default async function handler(req: NextRequest, res: NextResponse) {
    try {

        await res.revalidate('/');
        return res.json({ revalidated: true });

    } catch (err) {
        console.error(err);
        return res.status(500).send('Error revalidating');
    }
}

enter image description here

like image 756
artist.pradeep Avatar asked Oct 25 '25 10:10

artist.pradeep


1 Answers

Instead of NextRequest and NextResponse we must use NextApiRequest and NextApiResponse.

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
    try {

        await res.revalidate('/');
        return res.json({ revalidated: true });

    } catch (err) {
        return res.status(500).send('Error revalidating');
    }
}

like image 148
artist.pradeep Avatar answered Oct 27 '25 00:10

artist.pradeep