{"id":22946,"library":"vite-ssr","title":"Vite SSR","description":"vite-ssr is a lightweight library for server-side rendering with Vite, supporting Vue and React. Current stable version is 0.17.2, released in late 2022. It abstracts SSR complexity while staying unopinionated about routing and API logic, offering lightning-fast HMR even in SSR mode. Unlike heavier frameworks like Next.js or Nuxt, it integrates directly with Vite's plugin ecosystem and can be deployed to Node.js, serverless platforms (Vercel, Netlify), or edge runtimes like Cloudflare Workers. The package ships TypeScript types and requires Vite 4+.","status":"active","version":"0.17.2","language":"javascript","source_language":"en","source_url":"https://github.com/frandiox/vite-ssr","tags":["javascript","vite","ssr","vue","react","typescript"],"install":[{"cmd":"npm install vite-ssr","lang":"bash","label":"npm"},{"cmd":"yarn add vite-ssr","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-ssr","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; the library is a Vite plugin and needs Vite 4+","package":"vite","optional":false},{"reason":"Peer dependency for React projects using Vite 4","package":"@vitejs/plugin-react","optional":true},{"reason":"Peer dependency for Vue projects using Vite 4","package":"@vitejs/plugin-vue","optional":true},{"reason":"Peer dependency for Vue SSR projects","package":"vue-router","optional":true},{"reason":"Peer dependency for React SSR projects","package":"react-router-dom","optional":true}],"imports":[{"note":"ESM-only; CJS require will fail. Use 'vite-ssr/vue' or 'vite-ssr/react' for better type inference.","wrong":"const viteSSR = require('vite-ssr')","symbol":"viteSSR (default)","correct":"import viteSSR from 'vite-ssr'"},{"note":"Plugin is a default export, not named. Must use Vite config's plugins array.","wrong":"import { viteSSR } from 'vite-ssr/plugin.js'","symbol":"viteSSR plugin","correct":"import viteSSR from 'vite-ssr/plugin.js'"},{"note":"Framework-specific entry points are default exports for better type inference.","wrong":"import { viteSSR } from 'vite-ssr/vue'","symbol":"viteSSR from framework subpath","correct":"import viteSSR from 'vite-ssr/vue'"},{"note":"Type-only import to avoid runtime side effects.","wrong":"import { ViteSSRContext } from 'vite-ssr'","symbol":"viteSSR type","correct":"import type { ViteSSRContext } from 'vite-ssr'"}],"quickstart":{"code":"// vite.config.js\nimport vue from '@vitejs/plugin-vue'\nimport viteSSR from 'vite-ssr/plugin.js'\n\nexport default {\n  plugins: [viteSSR(), vue()],\n}\n\n// src/main.js\nimport App from './App.vue'\nimport { createRouter, createMemoryHistory, createWebHistory } from 'vue-router'\nimport viteSSR from 'vite-ssr/vue'\n\nconst routes = [\n  { path: '/', component: () => import('./Home.vue') },\n]\n\nexport default viteSSR(App, { routes }, (context) => {\n  const { app, router, initialState } = context\n  // Optional: Pinia store setup\n  // const pinia = createPinia()\n  // app.use(pinia)\n  // if (import.meta.env.SSR) {\n  //   initialState.pinia = pinia.state.value\n  // } else {\n  //   pinia.state.value = initialState.pinia || {}\n  // }\n})","lang":"typescript","description":"Shows minimal setup for Vue SSR with Vite: plugin config, entry file with router and SSR hook."},"warnings":[{"fix":"Update code that accesses `url` properties (e.g., `url.search` vs `url.searchParams`).","message":"In v0.15.0 the `url` object in SSR context changed from `Location` type to `URL` type.","severity":"breaking","affected_versions":">=0.15.0 <0.16.0"},{"fix":"Upgrade Vite to version 4, and migrate Vite config as per Vite migration guide.","message":"v0.17.0 dropped support for Vite 3; requires Vite 4+.","severity":"breaking","affected_versions":">=0.17.0"},{"fix":"Update package.json: replace 'react-router-config' and 'react-router-dom@5' with 'react-router-dom@6'. Adjust route config shape.","message":"react-router-dom v5 support is deprecated; migrate to v6.","severity":"deprecated","affected_versions":">=0.16.0 <0.17.0"},{"fix":"Use default import syntax.","message":"The plugin must be imported as `import viteSSR from 'vite-ssr/plugin.js'` (default export). Using named import causes runtime error.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to v0.14.2+ or manually sanitize state values.","message":"State serialization may fail if data contains already escaped characters (e.g., newlines). Fixed in v0.14.2.","severity":"gotcha","affected_versions":"<0.14.2"},{"fix":"Remove custom serializer functions; data is now JSON-serialized automatically.","message":"In v0.14.0 state serialization changed to JSON, breaking custom serialization logic.","severity":"breaking","affected_versions":">=0.14.0 <0.15.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Replace `const viteSSR = require('vite-ssr')` with `import viteSSR from 'vite-ssr'` in a file with .js or .mjs extension, and ensure `\"type\": \"module\"` in package.json.","cause":"Using CommonJS require instead of ESM import.","error":"Cannot find module 'vite-ssr' or its corresponding type declarations."},{"fix":"Upgrade to vite-ssr@0.17.2 or later.","cause":"__DEV__ global conflicts with Vite 4's define; fixed in v0.17.2.","error":"Error: [vite] Internal server error: __DEV__ is not defined."},{"fix":"Change import to `import viteSSR from 'vite-ssr/plugin.js'` (default export).","cause":"Using named export `{ viteSSR }` from plugin.js instead of default export.","error":"TypeError: Cannot destructure property 'app' of 'context' as it is undefined."},{"fix":"Update code to use URL API: e.g., `url.searchParams.get('q')` instead of `url.search`.","cause":"Accessing `url` properties assuming Location type after v0.15.0 breaking change.","error":"Error: [vite-ssr] The 'url' property is missing or invalid."},{"fix":"Downgrade React to 17 or use a compatible fork; check for updates on v0.18.0.","cause":"vite-ssr peer dependency requires React 17; React 18 is not officially supported.","error":"Warning: React version mismatch. Expected 17, got 18."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}