Vite error when importing from .server file. "Error: Server-only module referenced by client" #9035
Replies: 5 comments 18 replies
-
#8448 maybe you'll find something useful here |
Beta Was this translation helpful? Give feedback.
-
I am encountering a similar problem. Yet don't know if it's related.
Even though the specified import is only used within the action function. Everything works great when using optimizeDeps: {
entries: [
'**/routes/**/*.{ts,tsx}',
],
}, Anyone got an idea about this? |
Beta Was this translation helpful? Give feedback.
-
For what it's worth: I had a similar problem:
but it turned out, I had imported a function from the I assume this is because remix determines if an import from a .server.js file is actually used in the loader function when deciding to throw this error or not. |
Beta Was this translation helpful? Give feedback.
-
OK now I'm having trouble integrating Trigger.dev because their initialization, which is based on file name routing rather than folder name routing, triggers this error. The automatically generated import { createRemixRoute } from "@trigger.dev/remix";
import { client } from "~/trigger.server";
// Remix will automatically strip files with side effects
// So you need to *export* your Job definitions like this:
export * from "~/jobs/example.server";
export const { action } = createRemixRoute(client); And when I try to build I get the error:
Now, I don't think this should be an error and I think it's on the Remix side, but I'm not sure if anyone is working on this issue or if it's just not going to be fixed but I'd like to be able to integrate Remix with Trigger.dev so I'll try to see if they have any tips as well. |
Beta Was this translation helpful? Give feedback.
-
it also happens when you re-export route relevant modules imported from other file.
`+loader.tsx`
import { db, post } from '~/server/driver/db.server';
export const loader: LoaderFunction = async () => {
const result = await db.select().from(post).all();
return result;
};
...clientLoader, meta, etc `route.tsx`
...
export { loader, clientLoader, meta, shouldRevalidate } from './+loader'; I splitted +loader.file into two, one that exports export { clientLoader, meta, shouldRevalidate } from './+meta';
export { action, headers, loader } from './+server';
export default Route; |
Beta Was this translation helpful? Give feedback.
-
Hello.
I have a file named validation.server.jsx that I use to export a schema validation function.
As the name indicates, it is a .server file with code to run exclusively server-side.
I then use the exported function from the referred file to validate data inside the action of my route.jsx.
Now with Vite, Im getting the error below just by importing the function from the validation.server.jsx file into my app/routes/admin/route.jsx.
import { validateSchema } from "../../lib/validation.server"
By making this import I get the error or any import from a .server file into a route.jsx file i get the error:
It seems that it was dealt with before but im still getting this problem: #8267
Beta Was this translation helpful? Give feedback.
All reactions