Common Next.js errorsasync/await is not yet supported in Client Components
async/await is not yet supported in Client Components, only Server Components. A component in a 'use client' file was written as an async function, usually to fetch data straight inside it.
How to fix it
Fetch in a Server Component and pass the data down. If you want the page to start rendering before the data arrives, pass the promise and read it with React's use() inside Suspense:
Fetch on the server, read on the client // app/orders/page.tsx (Server Component)
import { Suspense } from 'react'
import { OrderList } from './order-list'
export default function Page() {
const orders = getOrders() // don't await: pass the promise
return (
<Suspense fallback={<p>Loading orders…</p>}>
<OrderList orders={orders} />
</Suspense>
)
}
// app/orders/order-list.tsx
'use client'
import { use } from 'react'
export function OrderList({ orders }: { orders: Promise<Order[]> }) {
const list = use(orders)
return <ul>{list.map((o) => <li key={o.id}>{o.ref}</li>)}</ul>
}
If the data really has to be fetched in the browser (it depends on something only the browser knows), fetch it in an effect or with a data library, and keep the component itself synchronous.