react-router-hono-server is a JavaScript/TypeScript library designed to integrate React Router v7 applications with Hono servers, primarily through a Vite plugin. It simplifies the setup of server-side rendering (SSR) and middleware for React Router, enabling development with Vite's Hot Module Replacement (HMR). The library is currently at version 2.25.3, with a release cadence that frequently updates to align with new versions of Hono and React Router. Its key differentiators include native support for React Router v7's unstable middleware API, broad deployment target compatibility (Node, Bun, Cloudflare Workers, AWS Lambda), and an opinionated but customizable default Hono server configuration. It strictly operates in ESM mode and leverages Vite for its build and development pipeline. The package relies on peer dependencies like `hono`, `react-router`, and `@hono/node-server` to function.
npm install react-router-hono-serverVerified import paths — ran on the pinned version, not inferred.
This shows how to integrate the `react-router-hono-server/dev` Vite plugin into your `vite.config.ts` to automatically generate a default Hono server for your React Router application, enabling HMR and production builds.
Ensure your project uses React Router v7. If migrating from v1, consult the migration guide in the package's GitHub repository.
Always use `import ... from '...'` syntax. Ensure your project is configured for ESM, including `type: 'module'` in `package.json` if running in Node.js.
Add `declare module 'react-router' { interface Future { v8_middleware: true; } }` to a TypeScript declaration file (e.g., `react-router.config.ts` or `src/globals.d.ts`).Manually install `hono` or add `public-hoist-pattern[]=hono` to your `.npmrc` file if using pnpm to ensure it's hoisted and discoverable.
Ensure `reactRouterHonoServer()` is included in the `plugins` array of your `vite.config.ts`.
Either use the default naming convention (`server.ts`) or specify your custom server entry point via `reactRouterHonoServer({ serverEntryPoint: './path/to/your/server.ts' })`.Add the type declaration `declare module 'react-router' { interface Future { v8_middleware: true; } }` to a global TypeScript declaration file in your project.Refactor all module imports to use ES module `import ... from '...'` syntax. Ensure your Node.js environment is configured to run ESM.
Create a `server.ts` file in your application's root directory, or specify the correct path to your server entry file using the `serverEntryPoint` option in `reactRouterHonoServer({ serverEntryPoint: './src/my-server-entry.ts' })` in `vite.config.ts`.Ensure `hono` is explicitly installed in your project (`npm install hono` or `yarn add hono`). If using pnpm, add `public-hoist-pattern[]=hono` to your `.npmrc` file.