Can no longer export types from 'use server' files
Answered
Gulf menhaden posted this in #help-forum
Gulf menhadenOP
There seems to be a recent breaking change that no longer allow types or non async functions to be exported from 'use server' directed files. I can obviously split this up so that I have three files
action-helpers.ts
actions.ts
action-types.ts
and only tag actions.ts as the 'use server' file and then have the other files have the helping content, but I'm curious as to why we MUST export ONLY async content and why we can't also export types related to those functions directly from the file itself.
This makes things like monkey wrapping React.cache and unstable_cache for aync calls on Prisma somewhat cumbersome (and it was already cumbersome to begin with).
I also like to export the Prisma.PromiseReturnType from those files directly. I was able to do this before my last update to @latest.
I'll make the changes, but just curious if this was an intended or unintended consequence of a recent change.
action-helpers.ts
actions.ts
action-types.ts
and only tag actions.ts as the 'use server' file and then have the other files have the helping content, but I'm curious as to why we MUST export ONLY async content and why we can't also export types related to those functions directly from the file itself.
This makes things like monkey wrapping React.cache and unstable_cache for aync calls on Prisma somewhat cumbersome (and it was already cumbersome to begin with).
I also like to export the Prisma.PromiseReturnType from those files directly. I was able to do this before my last update to @latest.
I'll make the changes, but just curious if this was an intended or unintended consequence of a recent change.
Answered by joulev
i think it is a bug. please report it.
if you export runtime values (consts, functions, classes, etc.), then you must only export async function and nothing else.
but if you just export types (which will be stripped at runtime), i don't see a reason why they need to ban that, so this is likely a bug.
if you export runtime values (consts, functions, classes, etc.), then you must only export async function and nothing else.
but if you just export types (which will be stripped at runtime), i don't see a reason why they need to ban that, so this is likely a bug.
3 Replies
@Gulf menhaden There seems to be a recent breaking change that no longer allow types or non async functions to be exported from 'use server' directed files. I can obviously split this up so that I have three files
action-helpers.ts
actions.ts
action-types.ts
and only tag actions.ts as the 'use server' file and then have the other files have the helping content, but I'm curious as to why we MUST export ONLY async content and why we can't also export types related to those functions directly from the file itself.
This makes things like monkey wrapping React.cache and unstable_cache for aync calls on Prisma somewhat cumbersome (and it was already cumbersome to begin with).
I also like to export the Prisma.PromiseReturnType from those files directly. I was able to do this before my last update to @latest.
I'll make the changes, but just curious if this was an intended or unintended consequence of a recent change.
i think it is a bug. please report it.
if you export runtime values (consts, functions, classes, etc.), then you must only export async function and nothing else.
but if you just export types (which will be stripped at runtime), i don't see a reason why they need to ban that, so this is likely a bug.
if you export runtime values (consts, functions, classes, etc.), then you must only export async function and nothing else.
but if you just export types (which will be stripped at runtime), i don't see a reason why they need to ban that, so this is likely a bug.
Answer
Gulf menhadenOP
let me confirm that, I know in some cases I had a helper function that was in there as well, but I'll make sure I don't export that and see if it's still causing an issue.
Gulf menhadenOP
@joulev you were 100% correct, it does allow the types. So I just need to modify some of my exports slightly to make it work. Thanks for the quick feedback.