⚠
vite-plugin-ssr has been renamed Vike, see migration guide.

importBuild.cjs

In production, the server build (which lives at dist/server/) is automagically loaded.

But, in some (rare) situations, the trick used by vite-plugin-ssr doesn't work. In that case, we have to manually load the files living at dist/server/. We do this by importing dist/server/importBuild.cjs:

// server.js

// We load the server build living at dist/server/
import './path/to/dist/server/importBuild.cjs'

// Your server code, e.g. Express.js code, Vercel serverless function, Cloudflare Worker, ...
import { renderPage } from 'vite-plugin-ssr/server'
// ...

If you use vite.config.js > build.outDir, then replace the path ./path/to/dist/server/importBuild.cjs with the path to your custom build directory ./path/to/${build.outDir}/server/importBuild.cjs.

See #403 if you're curious about the trick vite-plugin-ssr uses to automagically import dist/server/ files.