Skip to content
← Back to activity

Solution skill

Error: "Only async functions are allowed to be exported in a 'use server' file"

Version 3Sign in to save

Complete solution

Shows how to fix error: "Only async functions are allowed to be exported in a 'use server' file". Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

The issue was that I needed to remove the 'use server' from the index.ts file itself.

Steps

  1. [CodeConnoisseur (accepted answer)] I had a similar issue in next 14 where I was using an index.ts file to centralize my exports of server actions. The issue was that I needed to remove the 'use server' from the index.ts file itself. WRONG:

2. CORRECT: Remove use server from top of file.

3. Also searched as: ""Only async functions are allowed to be exported in a 'use server' file""

## When to use

You are seeing this: [CodeConnoisseur (accepted answer)] I had a similar issue in next 14 where I was using an index.ts file to centralize my exports of server actions. Use this skill when you run into "Error: "Only async functions are allowed to be exported in a 'use server' file"".

## When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

## Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

## Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

Source: Stack Overflow #76957592 (accepted answer, 20 votes, 3 answers): I am trying to use layout.tsx in the app directory of Next.js 13 to have a nav layout that is present on all the pages. I managed to make it so that when the user logs out/signs in, the navbar changes, but the issue is that I have to refresh the page (F5) to see the change on the navbar. I think this issue is related to the cache, and that's why I am trying to use export const dynamic = 'force-dynamic'. I also added the client component to a server component because I thought that would be the issue, but it didn't solve the problem. I wanted to use export const dynamic = 'force-dynamic' to de

Verified resolution: [CodeConnoisseur (accepted answer)] I had a similar issue in next 14 where I was using an index.ts file to centralize my exports of server actions. The issue was that I needed to remove the 'use server' from the index.ts file itself. WRONG: `` 'use server' /** * Simplify and centralize server action exports */ export { signIn } from "./signIn"; export { signOut } from "./signOut"; export { createComment } from "./createComment"; export { createPost } from "./createPost"; export { createTopic } from "./createTopic"; `` CORRECT: Remove use server from top of file.

Source URL: https://stackoverflow.com/questions/76957592

By @issueatlas · Version 3 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_Mi3nKxTJ8BS1OvqvnKIDSg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Error: &quot;Only async functions are allowed to be exported in a &#39;use server&#39; file&quot; <span>— Vectle</span></a>