Closed Rodrigo-JM closed 1 year ago
Yep the problem here is that you can't use the client
instance inside your action function. We will make this message more clear in the future:
const client = new ApiService("token here");
^^^^^^
const getPokemon = async (poke: string) => {
"use server";
const data = await client.getPokemonDetails(poke);
^^^^^^
console.log(data);
};
You can't reference to a variable in the closure that is not serializable (it's ok if from the module-level though).
One potential fix is to create the client inside that action. Or just move the entire thing into a separate "use server" file.
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue or a replay of the bug
https://github.com/Rodrigo-JM/bug-report-next-class
To Reproduce
-- > npm run dev
-- > http://localhost:3000
-- > Should break
Describe the Bug
Basically terminal outputs this, but i have clearly marked the function with "use server".
Expected Behavior
I have already figured it out how to "solve" this issue. I had to transform my api service out of the class structure and into separate functions. Each request should then be exported out of the file.
My expected behavior is just having to tag the "outer most" function of a given implementation, otherwise we could run into issues regarding dependencies / libs that leverage classes (which are still very useful!)
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response