-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A "use server" file can only export async functions' error when exporting non-async/cache functions #62926
Comments
The issue is caused by the stricter Repro: https://github.com/chungweileong94/next-use-server-bug |
yeah, i had to make sure i used the |
It seems like NextJS is doing next.js/packages/next/src/build/webpack/loaders/next-flight-loader/action-validate.ts Line 16 in 7f7943b
|
Its worth noting that this currently breaks the example shown in the documentation around using React.cache currently: https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#fetching-data-on-the-server-with-third-party-libraries |
This is a duplicate of #62860 - please give #62860 (comment) and #62821 a read. We'll keep everyone updated there. Basically it does not make sense to use |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:27 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T8103 Available memory (MB): 8192 Available CPU cores: 8 Binaries: Node: 20.10.0 npm: 10.2.3 Yarn: 1.22.21 pnpm: 8.15.4 Relevant Packages: next: 14.2.0-canary.2 // Latest available version is detected (14.2.0-canary.2). eslint-config-next: 14.1.2 react: 18.2.0 react-dom: 18.2.0 typescript: 5.3.3 Next.js Config: output: standalone
Which example does this report relate to?
none
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
When using the "use server" directive at the top of a file in a Next.js application, if the file exports a non-async function or a React cache function (e.g., React.cache), it throws the following error:
Error: A "use server" file can only export async functions.
Expected Behavior
The expected behavior is to allow exporting non-async functions and React cache functions from a file with the "use server" directive without any errors.
To Reproduce
StackBlitz
The text was updated successfully, but these errors were encountered: