Registry / devops / vite-plugin-cloudflare-functions

vite-plugin-cloudflare-functions

JSON →
library0.8.4jsnpmunverified

Vite plugin (v0.8.4) that makes Cloudflare Pages Functions work seamlessly with Vite, offering HMR, local dev with wrangler, and support for D1, R2, KV, and Durable Objects. Released ~monthly, it integrates Cloudflare's workers-types, generates TypeScript declarations, and allows configuration of persist-to, compatibility-date, and more. Key differentiator: provides a Vite-native experience for Cloudflare Pages Functions, enabling fast development with auto-reload and type generation. Requires Vite >=3.1.8, wrangler ^2.20.1 || ^3.0.0, and optional HTTP client.

npm install vite-plugin-cloudflare-functions
INSTALL
IMPORT
SIG · VITE-PLUGIN-CLOUDF
V
vite-plugin-cloudflare-functions
devopsjavascriptv0.8.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import CloudflareFunctions from 'vite-plugin-cloudflare-functions'
import { CloudflareFunctions } from 'vite-plugin-cloudflare-functions'
Default export; named export does not exist.
CloudflareFunctionsPlugin
import { type CloudflareFunctionsPlugin } from 'vite-plugin-cloudflare-functions'
import CloudflareFunctionsPlugin from 'vite-plugin-cloudflare-functions'
Type import for TypeScript; use 'import type' to avoid bundling.
defineCloudflareFunctionsConfig
import { defineCloudflareFunctionsConfig } from 'vite-plugin-cloudflare-functions/config'
import { defineCloudflareFunctionsConfig } from 'vite-plugin-cloudflare-functions'
Config helper is exported from a subpath.

Configures vite-plugin-cloudflare-functions with TypeScript support and a sample handler function.

// vite.config.ts import { defineConfig } from 'vite' import CloudflareFunctions from 'vite-plugin-cloudflare-functions' export default defineConfig({ plugins: [ CloudflareFunctions({ // Path to functions directory (default: 'src/functions') functionsDir: 'src/functions', // Generate TypeScript declarations (default: true) dts: true, // Enable local persistence for KV, D1, etc. persistTo: 'path/to/persist', // Set Cloudflare compatibility date compatibilityDate: '2024-12-01' }) ] }) // Example function: src/functions/hello.ts import { defineHandler } from 'vite-plugin-cloudflare-functions/handler' export const onRequest: PagesFunction = defineHandler({ async fetch(request, env, ctx) { return new Response('Hello from Cloudflare Functions!') } })
Debug
Known issues
gotchaPlugin requires wrangler to be installed, but it is a peer dependency; not auto-installed by npm.
fix
Run 'npm install --save-dev wrangler'.
affects: >=0.0.0
breakingIn v0.6.0, the plugin disables inheriting HTTP_PROXY / HTTPS_PROXY env variables by default, which may break proxied environments.
fix
Set 'inheritHttpProxy: true' in plugin options to restore old behavior.
affects: >=0.6.0
deprecatedThe 'ohmyfetch' package is obsolete; prefer 'ofetch'.
fix
Replace 'ohmyfetch' with 'ofetch' in your project.
affects: >=0.8.0
gotchaTypeScript declarations require an additional dependency '@cloudflare/workers-types' to function properly.
fix
Install '@cloudflare/workers-types' as a dev dependency.
affects: >=0.0.0
gotchaDurable Objects (DO) configuration changed in v0.7.0; the 'do' config format is more explicit.
fix
Update DO config to use the new schema as documented.
affects: >=0.7.0
gotchaPlugin uses 'mlly' for module loading; ensure your Node version meets the minimum (>=v18.16.0).
fix
Upgrade Node.js to v18.16.0 or later.
affects: >=0.0.0
deprecatedThe 'fast-glob' dependency has been updated to v3.3.3; older versions may cause globbing issues.
fix
Update vite-plugin-cloudflare-functions to >=0.8.3.
affects: <0.8.3
Errors
Common errors & fixes
Cannot find module 'vite-plugin-cloudflare-functions' or its corresponding type declarations.
Missing TypeScript declarations or module resolution issue.
fix
Install the package and ensure 'compilerOptions.moduleResolution' is set to 'bundler' or 'node' in tsconfig.json.
Error: The 'config' file is not found in the 'functions' directory.
Custom 'functionsDir' path does not exist or is misconfigured.
fix
Check the 'functionsDir' option in the Vite config and create the directory if needed.
Error: The 'wrangler' CLI is not installed.
Missing wrangler peer dependency.
fix
Run 'npm install --save-dev wrangler'.
Error: The environment variable is not set: CF_ACCOUNT_ID, CF_API_TOKEN
Missing Cloudflare credentials for production deployment.
fix
Set CF_ACCOUNT_ID and CF_API_TOKEN in your environment variables or .env file.
Error: The 'persistTo' directory path must be a string.
Incorrect type or format for the 'persistTo' option.
fix
Provide a string path, e.g., 'persistTo: './data/persist''.
Upgrade
Version history
0.8.4latest on npm
Audit
Dependencies
viterequiredPeer dependency of Vite plugin
wranglerrequiredRuntime dependency for Cloudflare Workers/Pages emulation
Agent activity
41 hits · last 30 days
node
36
Resources