Skip to content

[vite] Internal server error: Cannot find module 'cloudflare:workers' #305

@dinfer

Description

@dinfer

According to this article, It's very convenient to access env by import it from as a virtual module like this

import { env } from "cloudflare:workers";
import { drizzle } from "drizzle-orm/d1";

export const db = drizzle(env.DB); // you can access `db` variable anywhere

This feature is supported by vite-plugin-cloudflare, and it does not works in honox project with following vite config:

import build from '@hono/vite-build/cloudflare-workers'
import adapter from '@hono/vite-dev-server/cloudflare'
import tailwindcss from '@tailwindcss/vite'
import honox from 'honox/vite'
import { defineConfig } from 'vite'
import { cloudflare } from "@cloudflare/vite-plugin"; // import the official plugin

export default defineConfig({
  plugins: [
    honox({
      devServer: { adapter },
      client: { input: ['./app/style.css'] },
    }),
    tailwindcss(),
    build({}),
    cloudflare() // used here
  ],
})

The error is still there, and I think the @hono/vite-build/cloudflare-workers does not using workerd as runtime when i'm run the project using npm run dev. How can I use the cloudflare:workers package?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions