Replies: 1 comment 1 reply
-
It's not that resource routes will ever run on the client. It's what you export. Anything you export from a route module, except for |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We're trying to migrate a moderately complex Remix app to use Vite but the main blocker we're running into is that there is server code in our client bundles (
process
not defined style errors) and that Rollup fails with[commonjs--resolver] Server-only module referenced by client
.Important to note that these are not problems in Remix v2.9.1 unless you switch to
remix vite:dev
andremix vite:build
.The offending routes are resource routes that form our API endpoints. For example:
This route is a resource route and has no
default
export because it's designed to only ever run at the server.Each of these API endpoints export an object that describes the shape of the endpoint.
The client side of the API uses the types of these exports to infer the types for the request/response.
For this to work, the module must export the endpoint shape. This becomes problematic when those Zod schemas are imported from
.server
files.Technically we could hack around this by exporting the
typeof
the endpoint shape, or wrapping every endpoint definition inserverOnly$
macros but I think the bundling behaviour has changed for resource routes, which seems like a more important issue to address.A resource route won't ever run at the client side, right? So routes without default exports shouldn't ever be considered for client side bundling.
We can probably work around this by moving our API routes away from Remix, but the resource route model has worked so well up to this point, that it would be a shame to lose it all.
Would be great to get a clarification as to whether this is the intended behaviour and it's a known edge case when migrating from Remix Classic to Remix Vite, or whether this is something specific to our app.
Beta Was this translation helpful? Give feedback.
All reactions