ISR unstable_revalidate -- TypeError: res.hasHeader is not a function
See original GitHub issueVerify canary release
- I verified that the issue exists in Next.js canary release
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP Tue Jun 23 12:58:10 UTC 2020
Binaries:
Node: 14.17.3
npm: 6.14.13
Yarn: 1.22.17
pnpm: N/A
Relevant packages:
next: 12.1.5
react: 18.0.0
react-dom: 18.0.0
What browser are you using? (if relevant)
Chrome 102.0.5005.61
How are you deploying your application? (if relevant)
Vercel
Describe the Bug
I am attempting to use res.unstable_revalidate
to revalidate an ISR generated page. When invoking the function, the following error is returned ->
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
if (req.query.secret !== process.env.ISR_REVALIDATION) {
return res.status(401).json({ message: 'Invalid token' });
}
if (!req.body.path) {
return res
.status(400)
.json({ message: 'Please provide a path to revalidate' });
}
try {
await res.unstable_revalidate(req.body.path);
return res.json({
message: `${req.body.path} Revalidated`,
revalidated: true,
});
} catch (err) {
// If there was an error, Next.js will continue
// to show the last successfully generated page
return res.status(500).send('Error revalidating');
}
}
TypeError: res.hasHeader is not a function
The error will not be returned if I pass just the index route, /
. However, any other path that is passed in from a ISR page will return TypeError: res.hasHeader is not a function
Full stack trace
at handler (webpack-internal:///(api)/./src/pages/api/revalidate.ts:30:21)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Object.apiResolver (/node_modules/next/dist/server/api-utils/node.js:185:9)
at async DevServer.runApi (/node_modules/next/dist/server/next-server.js:404:9)
at async Object.fn (/node_modules/next/dist/server/base-server.js:507:37)
at async Router.execute (/node_modules/next/dist/server/router.js:212:36)
at async DevServer.run (/node_modules/next/dist/server/base-server.js:642:29)
at async DevServer.run (/node_modules/next/dist/server/dev/next-dev-server.js:514:20)
at async DevServer.handleRequest (/node_modules/next/dist/server/base-server.js:334:20)
Expected Behavior
To run the function and trigger a revalidation
To Reproduce
Trigger res.unstable_revalidate
and pass whatever path you want to revalidate.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top Results From Across the Web
res.revalidate() is not a function in NextResponse of Nextjs for ...
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 ...
Read more >Blog - Next.js 12.1
On-demand Incremental Static Regeneration (Beta). Next.js now exposes a function unstable_revalidate() allowing you to revalidate individual ...
Read more >Build a Restaurant Website with Next.js and Cosmic
On-demand Incremental Static Regeneration ISR. Next.js now exposes a function unstable_revalidate() allowing you to revalidate individual pages ...
Read more >Next.js On-Demand ISR // Full tutorial - YouTube
Next.js On-Demand ISR is was published in beta for Next.js version 12.1. In this video you will learn what On Demand ISR is,...
Read more >res.hasHeader is not a function - TechInPlanet
I've run into the error below when trying to use getServerSideProps to fetch data from an endpoint. Error: ERROR TypeError: res.hasHeader is ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, i’m going to prepare a reproduction reference app. I will send you the link soon.
This seems to happen if the provided url path points to a route that is a server side rendered page. And looking at the comment here of @bejarano-tech, it probably also happens when the route no fallback defined getStaticPaths . If this is the case, it would be nice to have better error handling for it.