next.js: [NEXT-1167] Server Actions 405 "Method Not Allowed" when using generateStaticParams
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP PREEMPT_DYNAMIC Wed, 26 Apr 2023 20:50:14 +0000
Binaries:
Node: 18.16.0
npm: 9.5.1
Yarn: 1.22.19
pnpm: N/A
Relevant packages:
next: 13.4.1
eslint-config-next: 13.0.6-canary.1
react: 18.2.0
react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Server actions. It seems like server actions wasn’t part of the issue form dropdown earlier
Link to the code that reproduces this issue
https://github.com/arduano/server-actions-repro
To Reproduce
npm install
npm run dev
- Open
/asdf
in the browser - Click the button, observe the network requests in the browser’s dev tools
Describe the Bug
Including generateStaticParams
in a page breaks server actions, making it return 405 on each request
Expected Behavior
The server actions behave as expected
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: 51
- Comments: 30 (1 by maintainers)
Commits related to this issue
- generateStaticParams causes issues with server actions https://github.com/vercel/next.js/issues/49408 — committed to jmenges/store by jmenges a year ago
- fix: server actions initiated from static pages (#51534) ### What? Pages marked with `generateStaticParams` don't currently support server actions, and instead return a 405 Method Not Allowed, with n... — committed to vercel/next.js by ztanner 10 months ago
Trying to do internationalization, and in my end the same problem.
I am using generateStaticParams in the root layout, then server actions in all my routes get 405 method not allowed.
Removing generateStaticParams make it works, but it is not a fix as i need this for locales.
This is related to : https://github.com/vercel/next.js/issues/49373#issuecomment-1592656952
Error happens in production too, just not printing anything in server console (browser console and network tab still show 405)
This error occurs in development only. Try building the app then running it in production, it will work just fine.
Hi, can confirm just had the same bug. The moment I remove generateStaticParams from the page the action works.
Also, I have the same issue. I am removing the generateStaticParams function, and the server action works property. Why can’t we use both generateStaticParams and server actions?
405 error in production on [POST] from Vercel logs. Page renders static content correctly then errors on Server action POST…
We are talking about it in the next-intl repo as well: https://github.com/amannn/next-intl/discussions/353
I think next.js should look into this if they plan to release server actions as beta or stable soon
Didn’t find this issue at first because it doesn’t include the error message I am getting. In case anyone else gets the same error message, here it is:
Bump
Is there anybody from Next on this issue? Happy to look into into it.
I found a workaround
You can currently bypass the error by turning your page from
mypath/page.tsx
tomypath/[[...slug]].tsx
. This optional catch-all segment makes “/mypath” still accessible and magically works, by telling Next.js: This page must be dynamic. Inside of the route’spage.tsx,
you can then make sure that only “/mypath” is matched by using notFound:Made a YT video as well: https://youtu.be/K6Jn24FsZFc