HonoH
Hono11mo ago
dan—1106

Honox + Vite + Prisma

When I try to use Prisma client libraries,

I get errors in my dev server:
module is not defined
    at eval (/home/ubuntu/projects/admin/node_modules/@prisma/debug/dist/index.js:30:1)
    at instantiateModule (file:///home/ubuntu/projects/admin/node_modules/vite/dist/node/chunks/dep-CHZK6zbr.js:52974:11


When I try to deploy, I get errors:
  Uncaught Error: No such module ".prisma/client/index-browser".
    imported from "index.js"
   [code: 10021]


This is my vite.config.ts file:
import build from "@hono/vite-build/cloudflare-workers";
import honox from "honox/vite";
import adapter from "@hono/vite-dev-server/cloudflare";
import { defineConfig } from "vite";
import { getPlatformProxy } from "wrangler";

export default defineConfig(async ({ command }) => {
  const platformProxy =
    command === "serve"
      ? await getPlatformProxy({
          environment: "prod",
          configPath: "wrangler.json",
        })
      : null;

  const devServerConfig = platformProxy
    ? {
        adapter: {
          env: platformProxy.env,
          onServerClose: platformProxy.dispose,
        },
      }
    : { adapter };

  return {
    plugins: [
      honox({
        devServer: devServerConfig,
      }),
      build(),
    ],
  };
});


These are my npm scripts:
  "scripts": {
    "dev": "vite",
    "build": "vite build --mode client && vite build",
    "preview": "npm run build && wrangler dev",
    "deploy": "npm run build && wrangler deploy --env prod",
    "db:migrate": "npx tsx prisma/migrate.ts"
  },


I can make the dev server work by setting ssr.external to a list of the prisma libraries, but that doesn't solve the prod deployment.

What's the right vite config to get Prisma working well with Cloudflare Workers + Honox?
Was this page helpful?