Why do I encounter "server actions that must be asynchronous functions" ? #80293
Replies: 1 comment 1 reply
-
Hey! I totally get where you’re coming from — this behavior with export enum and server actions in Next.js can be really confusing at first. When you export an enum inside a file marked with 'use server', it’s not an async function, it’s a TypeScript construct that compiles into regular JavaScript code. This breaks Next.js’s expectation that all exports in a server actions file are async functions. Why enums specifically? What should you do? This way: Your server actions file only exports async functions. Enums live in a plain module, so no conflicts. Your code stays clean and organized. Why is it designed this way? TL;DR Exporting enums in the same file causes build errors because enums are not async functions. Move enums to a separate file without 'use server' and import them. This is expected behavior for now. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Hello, everyone, I'm new
next.js
andreact
,I encountered a problem that may be low-level but I have been unable to understand like this. I worte alog.ts
to record all error in front-end by send request to backendIf I comment out
export enum ...
, my project will run well. But when I don't comment outexport enum ...
, it will show:I think
use server
allows exporting types but not enum, which is crazy. It means I need to write my large number of enum in another file and import them?I hope someone can help me answer my doubts or explain why it is designed in this way,thanks!
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions