Server Actions Fail to Import Members from Packages in Monorepo #58371
Replies: 1 comment
-
So I still have that issue on 14.2.23. (I am using Prisma though) and its unable to find the prisma db client And even though similar things are mentioned in other threads and they praise setting esmExternals: false. It did not work for me. However I realised it only happens for some server actions and only to those which where on a route where the there was no layout and the page.tsx was client side or did not fetch anything from the database and did not import the database client. I assume it might be because of what is written here
So for me making sure that the page.tsx or layout.tsx (from which I am calling the server-action) is using the database helped. just placing that here if someone is stumbling upon that problem themself |
Beta Was this translation helpful? Give feedback.
-
Summary
The issue
I have a turborepo set up with one nextjs app and a database package.
I can successfully use the database packing in server components and api routes, but when I use it in a server action there is an error. For some reason it can't seem to import anything from the database package.
Repo
liquiFruit/like-it-wear-it
@feat/add-db
Successfully using the package in RSC
Here I have an RSC page that can import and use the
getUsers
function from the database package.Error using the package in a server action
Here I have a client component with a
onClick
event handler on a button. This event handler calls a server actiontryCreateUser
, which in turn calls a function from the database package.A (terrible) solution
Upon moving
"use server"
into the database package, the client component can directly import the functioncreateUser
from the database package and successfully invoke it.Conclusion
This is terrible for many reasons:
db
,schema
, etc)Additional information
Example
https://github.com/liquiFruit/like-it-wear-it/tree/feat/add-db
Beta Was this translation helpful? Give feedback.
All reactions