-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Next.js RSC import error: 'swr' does not contain a default export (imported as 'useSWR') #2694
Comments
The reason is that it was added in v2.2.0 with the Next.js support React Server Component and use
This is probably a intentional and can be avoided by adding "use client". + "use client";
import useSWR from "swr";
export default function Home() {
const { isLoading } = useSWR("https://httpstat.us/200");
if (isLoading) {
return <div>Loading...</div>;
}
return <div>Loaded</div>;
} However, the error messages are confusing and need to be improved. |
@azu Thanks for your reproduction and explanation. ❤️
How to use
|
Also need to document that in server components, so far only key serialization APIs are available |
Is there a workaround for codegen workflows? I'm getting this here from Orval (issue referenced above) but even though the component importing this code is "use client" I'm still seeing build failures. If not, I may just need to fork Orval or do some hacky search+replace or just stop using codegen 🤷 |
I have added the "use client" to my swr setup but I am still getting the Error: Attempted to call the default export of C:\Users\USER\Desktop\campusBite\campus-bite\hooks\useCategory.ts from the server but it's on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component. |
./node_modules/@clerk/shared/dist/react/index.mjs |
Description / Observed Behavior
When import swr in nextjs react server component. It will throw a confusing error
'swr' does not contain a default export (imported as 'useSWR')
The text was updated successfully, but these errors were encountered: