Using drizzle postgres with trpc in Next.js app

I'm getting the following error with the below code: Module not found: Can't resolve 'dns'. For some reason, my Next.js app is trying to load drizzle on the client where it doesn't have access to Node modules. Has anyone ever run into this before?


import { publicProcedure, router } from "../trpc";
import { z } from "zod";

import { drizzle } from "drizzle-orm/node-postgres";

// If I comment out this function, the error goes away.
export const createDbClient = () => {
  return drizzle(process.env.DB_URL!);
};

const formSchema = z.object({
  name: z.string().min(1, "Must provide a name."),
  email: z.string().email(),
});

export const formRouter = router({
  test: publicProcedure.query(() => {
    return `test`;
  }),
  submit: publicProcedure.input(formSchema).mutation(({ input }) => {
    // const client = createDbClient();

    return `received form values`;
  }),
});

export type FormRouter = typeof formRouter;
Was this page helpful?