错误:此环境不支持服务器操作。请确保服务器已配置为处理对 /_next/data/... 端点的 POST 请求。
Error: Server Actions are not supported in this environment. Ensure the server is configured to handle POST requests to the /_next/data/... endpoint.
ID: nextjs/missing-server-actions-endpoint
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Next.js 13.4+ | active | — | — | — |
| Next.js 14.x | active | — | — | — |
| Next.js 15.x | active | — | — | — |
根因分析
服务器操作要求 Next.js 服务器处理对 /_next/data/... 端点的 POST 请求,但部署(例如静态导出、自定义服务器或边缘运行时)不支持此操作。
English
Server Actions require the Next.js server to handle POST requests to the /_next/data/... endpoint, but the deployment (e.g., static export, custom server, or edge runtime) does not support this.
官方文档
https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions#server-actions-with-static-export解决方案
-
Ensure the deployment supports Server Actions: use Node.js runtime (not edge) and avoid static export. In next.config.js, set `experimental.serverActions: true` if on Next.js 13/14, or remove the flag in 15+. For static export, switch to API routes.
-
Refactor the Server Action to an API route: create a route handler at app/api/action/route.ts and call it from the client with fetch.
无效尝试
常见但无效的做法:
-
70% 失败
'use server' must be in a separate file or at the top of a server component; client components cannot directly export server actions.
-
90% 失败
This prevents the server from processing the action entirely, breaking the feature.
-
60% 失败
Server Actions are designed to be invoked via form actions or the useTransition hook, not raw fetch; this bypasses security and serialization.