Replies: 2 comments
-
Use "use server" at the top of your server-only modules. Never import server modules into client components. Keep clean separation between client/server files. Access server code from client via API routes or server actions. |
Beta Was this translation helpful? Give feedback.
-
Hi, Sorry the other answer is not really helpful, and nor is it addressing your issue at all.
exports from Route Handlers are also checked at build time and cause errors if unexpected exports are found, in part to prevent a layer where route.ts exports so many things that it can end up leaking to client side, through transitive dependencies, this way you are forced to have a utils-kind-of-file, that the bundler can then allocated appropriately.
The base answer is you shouldn't have to, but of course in a large application, code might end up being imported by client side modules, so you can enforce certain rules, for example with Using
That means, that while yes you are declaring this module to be still wrapped on the server module graph, in spite of it potentially being imported to client side modules ( It is not wrong though, you can do it, you just need to know the implications. Is it possible though, that Try adding |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I have a directory
server
where I put server-side code, which si imported fromroute.ts
. I need to call node.js API from there (such asnode:fs/promises
).However this fails with:
How can I mark that files under
server/
directory should only run on the server?Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions