Open dante01yoon opened 1 year ago
I had a similar issue, removing async
from the component fixed it for me.
But we need it to be async in order to use await.
Same error using next-intl in Server component. if the component is not async it works.
But we need it to be async in order to use await.
@Vethavear If the function is async, you can just await the promise instead of wrapping it with use
.
@lshearer Not sure what you meant by your comment, because there are two options I see, and none of them manage to solve our issue:
use()
, which is still marked as beta/experimental - wouldn't use it in prod (also, I'm not 100% sure how it works under the hood, and using Promises gives me more control, eg. run multiple requests in parallel with Promise.all
)async
and await
the Promise - in which case we get the error the OP posted about.Same error using next-intl in Server component. if the component is not async it works.
You can solve it by the below link: https://next-intl-docs.vercel.app/docs/environments/server-client-components#async-components
Same error using next-intl in Server component. if the component is not async it works.
useTranslations not working for server component with async you might need to use getTranslations
from next-intl/server
instead . take a look in this link https://next-intl-docs.vercel.app/docs/environments/server-client-components#async-components
please , remove async syntax
before
export const Post = async () => {
const posts = use(getPosts())
......
}
after
export const Post = () => {
const posts = use(getPosts())
......
}
Thanks for input guys, I guess this is outdated now as we can use getTranslations from next-intl/server
Thanks
please , remove async syntax
- before
export const Post = async () => { const posts = use(getPosts()) ...... }
- after
export const Post = () => { const posts = use(getPosts()) ...... }
Thanks I had the same problem and this fix worked for me
In my case, the fix was to use const locale = await getLocale()
instead.
In my case, I had the getLocale() and getTranslations() working correctly. But I had to modify the root layout.js file:
before: export default async function RootLayout({ children }) {}
after:export default function RootLayout({ children }) {}
// error
export default async function Page() {
const t = useTranslations();
}
// ok (remove async)
export default function Page() {
const t = useTranslations();
}
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue or a replay of the bug
--
To Reproduce
app/post/post.tsx
and this is where post component is used.
app/post/page.tsx
Describe the Bug
Expected Behavior
when remove async keyword in component, error not thrown.
Is it intended?
wonder why this
Which browser are you using? (if relevant)
Chrome 114.0.5735.106 (arm64)
How are you deploying your application? (if relevant)
localhost - yarn dev (development mode)