Skip to content

Server-only module referenced by client -- how to fix? #324

Closed Answered by sergiodxa
ivan-kleshnin asked this question in Q&A
Discussion options

You must be logged in to vote

How to fix the above?

Always create those functions in a separate file, not in route files, route files contain route code only.

And you can name the file .server.ts to tell the compiler it's a server-only module

How Vite decides what modules are "Server-only"?

The compiler knows what exports from route are server-only (like a loader or action) and removes them when creating the client code, then it removes any unused code left after removing the server-only exports

If you add that authenticate function in your route and export it, the bundler will leave it there because something may depend on it

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ivan-kleshnin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants