Registry /
devops / vite-plugin-cloudflare-functions
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
muslnode 18–223 runs
build_error
glibcnode 18–223 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!')
}
})
Errors
Common errors & fixes
Cannot find module 'vite-plugin-cloudflare-functions' or its corresponding type declarations.
Missing TypeScript declarations or module resolution issue.
fixInstall 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.
fixCheck the 'functionsDir' option in the Vite config and create the directory if needed.
Error: The 'wrangler' CLI is not installed.
Missing wrangler peer dependency.
fixRun 'npm install --save-dev wrangler'.
Error: The environment variable is not set: CF_ACCOUNT_ID, CF_API_TOKEN
Missing Cloudflare credentials for production deployment.
fixSet 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.
fixProvide a string path, e.g., 'persistTo: './data/persist''.
Audit
Dependencies
viterequiredPeer dependency of Vite plugin
wranglerrequiredRuntime dependency for Cloudflare Workers/Pages emulation