Skip to content

Documentation for using Prisma with honox #260

Description

@dan-massey

What is the feature you are proposing?

I have successfully updated my vite.config.ts file to work with Cloudflare D1 and Prisma.

import build from "@hono/vite-build/cloudflare-workers";
import adapter from "@hono/vite-dev-server/cloudflare";
import honox from "honox/vite";
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(),
    ],
    ssr: {
      external: [
        "@prisma/adapter-d1",
        "@prisma/debug",
        "@prisma/driver-adapter-utils",
        "@prisma/client",
        "@auth/prisma-adapter",
      ],
    },
  };
});

This works locally in development, but when I try to deploy to Cloudflare Workers I get an error:

✘ [ERROR] A request to the Cloudflare API (/accounts/b74ef356e795bbe93a6c96f17a1d0e37/workers/scripts/sutro-admin/versions) failed.

  Uncaught Error: No such module "@prisma/client".
    imported from "index.js"
   [code: 10021]

I've used D1 + Prisma + Hono + Cloudflare Workers successfully in the past. Is there a trick to getting Prisma to work with Vite/honox?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions