Next.js Discord

Discord Forum

Is it possible to export types out of `server-only` files and import the types in `use client` comp?

Unanswered
Black carp posted this in #help-forum
Open in Discord
Black carpOP
Is it possible to export types out of server-only files and import the types in use client comp?
I tried to just do that beacsue it should work but I get nextjs erorr about server-only import in use client component...

6 Replies

Black carpOP
But in dev I’m getting error is there a specific way of dealing with it?
@alfonsüs ardani
show code?
how did u export it
Black carpOP
@alfonsüs ardani
// client/page.tsx
"use client";
import { type ISchema } from "./validation";
...rest of client code...



// validation.ts
import "server-only";
import z from "zod";

const zodSchema = z.object({ ... });

export type ISchema = z.infer<typeof zodSchema>;

// this is used in a different server component
export default zodSchema;