{"id":22611,"library":"vite-plugin-cloudflare-functions","title":"vite-plugin-cloudflare-functions","description":"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.","status":"active","version":"0.8.4","language":"javascript","source_language":"en","source_url":"https://github.com/yjl9903/vite-plugin-cloudflare-functions","tags":["javascript","cloudflare","vite","cloudflare-workers","cloudflare-pages","typescript"],"install":[{"cmd":"npm install vite-plugin-cloudflare-functions","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-cloudflare-functions","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-cloudflare-functions","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency of Vite plugin","package":"vite","optional":false},{"reason":"Runtime dependency for Cloudflare Workers/Pages emulation","package":"wrangler","optional":false}],"imports":[{"note":"Default export; named export does not exist.","wrong":"import { CloudflareFunctions } from 'vite-plugin-cloudflare-functions'","symbol":"default","correct":"import CloudflareFunctions from 'vite-plugin-cloudflare-functions'"},{"note":"Type import for TypeScript; use 'import type' to avoid bundling.","wrong":"import CloudflareFunctionsPlugin from 'vite-plugin-cloudflare-functions'","symbol":"CloudflareFunctionsPlugin","correct":"import { type CloudflareFunctionsPlugin } from 'vite-plugin-cloudflare-functions'"},{"note":"Config helper is exported from a subpath.","wrong":"import { defineCloudflareFunctionsConfig } from 'vite-plugin-cloudflare-functions'","symbol":"defineCloudflareFunctionsConfig","correct":"import { defineCloudflareFunctionsConfig } from 'vite-plugin-cloudflare-functions/config'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite'\nimport CloudflareFunctions from 'vite-plugin-cloudflare-functions'\n\nexport default defineConfig({\n  plugins: [\n    CloudflareFunctions({\n      // Path to functions directory (default: 'src/functions')\n      functionsDir: 'src/functions',\n      // Generate TypeScript declarations (default: true)\n      dts: true,\n      // Enable local persistence for KV, D1, etc.\n      persistTo: 'path/to/persist',\n      // Set Cloudflare compatibility date\n      compatibilityDate: '2024-12-01'\n    })\n  ]\n})\n\n// Example function: src/functions/hello.ts\nimport { defineHandler } from 'vite-plugin-cloudflare-functions/handler'\n\nexport const onRequest: PagesFunction = defineHandler({\n  async fetch(request, env, ctx) {\n    return new Response('Hello from Cloudflare Functions!')\n  }\n})","lang":"typescript","description":"Configures vite-plugin-cloudflare-functions with TypeScript support and a sample handler function."},"warnings":[{"fix":"Run 'npm install --save-dev wrangler'.","message":"Plugin requires wrangler to be installed, but it is a peer dependency; not auto-installed by npm.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Set 'inheritHttpProxy: true' in plugin options to restore old behavior.","message":"In v0.6.0, the plugin disables inheriting HTTP_PROXY / HTTPS_PROXY env variables by default, which may break proxied environments.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Replace 'ohmyfetch' with 'ofetch' in your project.","message":"The 'ohmyfetch' package is obsolete; prefer 'ofetch'.","severity":"deprecated","affected_versions":">=0.8.0"},{"fix":"Install '@cloudflare/workers-types' as a dev dependency.","message":"TypeScript declarations require an additional dependency '@cloudflare/workers-types' to function properly.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Update DO config to use the new schema as documented.","message":"Durable Objects (DO) configuration changed in v0.7.0; the 'do' config format is more explicit.","severity":"gotcha","affected_versions":">=0.7.0"},{"fix":"Upgrade Node.js to v18.16.0 or later.","message":"Plugin uses 'mlly' for module loading; ensure your Node version meets the minimum (>=v18.16.0).","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Update vite-plugin-cloudflare-functions to >=0.8.3.","message":"The 'fast-glob' dependency has been updated to v3.3.3; older versions may cause globbing issues.","severity":"deprecated","affected_versions":"<0.8.3"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install the package and ensure 'compilerOptions.moduleResolution' is set to 'bundler' or 'node' in tsconfig.json.","cause":"Missing TypeScript declarations or module resolution issue.","error":"Cannot find module 'vite-plugin-cloudflare-functions' or its corresponding type declarations."},{"fix":"Check the 'functionsDir' option in the Vite config and create the directory if needed.","cause":"Custom 'functionsDir' path does not exist or is misconfigured.","error":"Error: The 'config' file is not found in the 'functions' directory."},{"fix":"Run 'npm install --save-dev wrangler'.","cause":"Missing wrangler peer dependency.","error":"Error: The 'wrangler' CLI is not installed."},{"fix":"Set CF_ACCOUNT_ID and CF_API_TOKEN in your environment variables or .env file.","cause":"Missing Cloudflare credentials for production deployment.","error":"Error: The environment variable is not set: CF_ACCOUNT_ID, CF_API_TOKEN"},{"fix":"Provide a string path, e.g., 'persistTo: './data/persist''.","cause":"Incorrect type or format for the 'persistTo' option.","error":"Error: The 'persistTo' directory path must be a string."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}