Registry / devops / vite-plugin-fastify

vite-plugin-fastify

JSON →
library1.2.6jsnpmunverified

Vite plugin for Fastify with Hot Module Replacement (HMR) support. Version 1.2.6 is current; release cadence is low (occasional updates). Integrates Fastify server into Vite dev and build pipelines. Key differentiator: provides HMR for Fastify routes during development, unlike vanilla Fastify setup. Does not support WebSocket; use vite-node as workaround. Ships TypeScript declarations, ESM-only. Requires Vite and Fastify as peer dependencies.

npm install vite-plugin-fastify
INSTALL
IMPORT
SIG · VITE-PLUGIN-FASTIF
V
vite-plugin-fastify
devopsjavascriptv1.2.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
import fastify from 'vite-plugin-fastify'
const fastify = require('vite-plugin-fastify')
Package is ESM-only; CommonJS require is not supported.
fastify
import fastify from 'vite-plugin-fastify'
Default export only; no named exports.
type
import type { VitePluginFastifyOptions } from 'vite-plugin-fastify'
TypeScript types are bundled; use type import for options interface.

Sets up Vite with vite-plugin-fastify, defines a Fastify app with a route, and starts the server with HMR.

// vite.config.ts import { defineConfig } from 'vite'; import fastify from 'vite-plugin-fastify'; export default defineConfig({ plugins: [ fastify({ appPath: './src/app.ts', serverPath: './src/server.ts', }), ], }); // src/app.ts import fastify from 'fastify'; export default () => { const app = fastify(); app.get('/api/hello', async (req, reply) => { return reply.send('Hello, World!'); }); return app; }; // src/server.ts import app from './app'; const server = app(); const start = async () => { try { await server.listen({ host: '127.0.0.1', port: 3000 }); } catch (err) { server.log.error(err); } }; start();
Debug
Known issues
gotchaPlugin does not support WebSocket connections.
fix
Use vite-node instead of Vite dev server: change script to 'vite-node -w src/server.ts'. Disable devMode with { devMode: false } if needed.
affects: >=0.0.0
gotchaFile-based routing with @fastify/autoload not supported during build.
fix
Use import.meta.glob or consider vite-plugin-fastify-routes for file-based routing.
affects: >=0.0.0
gotchaServer must implement import.meta.hot dispose for proper cleanup during HMR.
fix
Add import.meta.hot.dispose and on('vite:beforeFullReload') handlers to close the server.
affects: >=0.0.0
gotchaDefault export must be a factory function returning the Fastify instance.
fix
Ensure app.ts exports a function that creates and returns the Fastify instance.
affects: >=0.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module not supported
Using CommonJS require() on ESM-only package.
fix
Use import syntax or convert project to ESM (add "type": "module" to package.json).
TypeError: (0 , fastify_1.default) is not a function
Incorrect import style: using default import with wrong syntax.
fix
Use correct ESM default import: import fastify from 'vite-plugin-fastify'.
Upgrade
Version history
1.2.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
vite-plugin-fastify — npm install vite-plugin-fastify · libregistry