next.js: Dynamic routing fails in production v.13.1.2 (Error: invariant: invalid Cache-Control duration provided: 0 < 1)
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:20:05 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T8101
Binaries:
Node: 16.17.1
npm: 8.15.0
Yarn: 1.22.11
pnpm: N/A
Relevant packages:
next: 13.1.2
eslint-config-next: 13.0.4
react: 18.2.0
react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue
///
To Reproduce
- Install v. 13.1.2
- Add dynamic route (e.g. [slug] folder)
- Build and run it in production mode
Returns the following error:
Error: invariant: invalid Cache-Control duration provided: 0 < 1
at Object.setRevalidateHeaders (/Users/lasse/Repos/aihelperbot.com/node_modules/next/dist/server/send-payload/revalidate-headers.js:13:19)
at Object.sendRenderResult (/Users/lasse/Repos/aihelperbot.com/node_modules/next/dist/server/send-payload/index.js:62:33)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Error: invariant: invalid Cache-Control duration provided: 0 < 1
at Object.setRevalidateHeaders (/Users/lasse/Repos/aihelperbot.com/node_modules/next/dist/server/send-payload/revalidate-headers.js:13:19)
at Object.sendRenderResult (/Users/lasse/Repos/aihelperbot.com/node_modules/next/dist/server/send-payload/index.js:62:33)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Error: invariant: invalid Cache-Control duration provided: 0 < 1
at Object.setRevalidateHeaders (/Users/lasse/Repos/aihelperbot.com/node_modules/next/dist/server/send-payload/revalidate-headers.js:13:19)
at Object.sendRenderResult (/Users/lasse/Repos/aihelperbot.com/node_modules/next/dist/server/send-payload/index.js:62:33)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Error: invariant: invalid Cache-Control duration provided: 0 < 1
at Object.setRevalidateHeaders (/Users/lasse/Repos/aihelperbot.com/node_modules/next/dist/server/send-payload/revalidate-headers.js:13:19)
at Object.sendRenderResult (/Users/lasse/Repos/aihelperbot.com/node_modules/next/dist/server/send-payload/index.js:62:33)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Describe the Bug
Returns white screen of death for dynamic routes with the error message: “Internal Server Error”.
I verified that the issue exists in the latest Next.js canary release *
It exist in “stabile” release.
Expected Behavior
Render dynamic routes without issue.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 12
- Comments: 17 (4 by maintainers)
Experiencing the same. Can view my repo where it’s happening at https://github.com/DavidTParks/vamp
Had to downgrade to 13.1.1 while a fix is sorted.
I also began experiencing this with 13.1.2 and came here to find this report
Hi, this has been updated in
v13.1.3-canary.5
of Next.js to show a proper error explaining what is occurring better.The problem here is that the dynamic path is being statically generated during the build and then dynamic server methods are being used during runtime e.g.
cookies()
orheaders()
fromnext/headers
.If these are being used in a shared library and the page is meant to be statically generated then
export const dynamic = 'force-static'
can be used to prevent this error or alternatively if the page isn’t meant to be statically generated and these methods are neededexport const dynamic = 'force-dynamic'
can be leveraged.I ran into this. Had to install next stable (13.1.2) and then reinstall next@canary. It was some sort of caching/versioning issue.
I see, in my case my root layout was accessing cookies, whereas some individual pages were not themselves, so next detected them as static. I’m going to force dynamic on all pages to solve this for now and may revisit this in the future to balance out static/dynamic pages.
That did not help unfortunately.
you can try to set the revalidate, refer to the document https://beta.nextjs.org/docs/api-reference/segment-config#revalidate