Files
next.js/errors/invalid-use-server-value.mdx
T
Delba de OliveiraGitHubgraphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>Joseph
24434f18db Docs: Add Data Security Guide (#80249)
Closes: https://linear.app/vercel/issue/DOC-4678/guide-data-security

Please merge this PR first: https://github.com/vercel/next.js/pull/80242

---------

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: Joseph <[email protected]>
2025-06-10 06:52:38 -05:00

44 lines
1.3 KiB
Plaintext

---
title: 'Invalid "use server" Value'
---
## Why This Error Occurred
This error occurs when a `"use server"` file exports a value that is not an async function. It might happen when you unintentionally export something like a configuration object, an arbitrary value, or missed the `async` keyword in the exported function declaration.
These functions are required to be defined as async, because `"use server"` marks them as [Server Actions](/docs/app/getting-started/updating-data) and they can be invoked directly from the client through a network request.
Examples of incorrect code:
```js
'use server'
// ❌ This is incorrect: only async functions are allowed.
export const value = 1
// ❌ This is incorrect: missed the `async` keyword.
export function getServerData() {
return '...'
}
```
Correct code:
```js
'use server'
// ✅ This is correct: an async function is exported.
export async function getServerData() {
return '...'
}
```
## Possible Ways to Fix It
Check all exported values in the `"use server"` file (including `export *`) and make sure that they are all defined as async functions.
## Useful Links
- [Server Actions and Mutations - Next.js](/docs/app/getting-started/updating-data)
- ['use server' directive - React](https://react.dev/reference/react/use-server)