What is this?
This Vite plugin automatically loads your server build (i.e. your files at dist/server/
).
Vite-plugin-ssr and Telefunc automatically add this plugin to your Vite app.
Manual import
Usually this Vite plugin is able to automatically import your server build (i.e. your files at dist/server/
) — there is nothing for you to do.
But the plugin doesn't work if you use Yarn PnP and you'll keep getting following error. The workaround is to manually import your server build.
# Yarn PnP users always get this error:
[@brillout/vite-plugin-import-build][Wrong Usage] Cannot find server build. (Re-)build your app
and try again. If you still get this error, then you may need to manually import the server build.
⚠️ If you aren't using Yarn PnP and you keep getting this error, then it's a bug that should be fixed — please open a new issue.
To manually import your server build:
// server.js
// Load server build, see https://github.com/brillout/vite-plugin-import-build#manual-import
import './path/to/dist/server/importBuild.cjs'
// Your server code (Express.js, Vercel Serverless/Edge Function, Cloudflare Worker, ...)
// ...
Make sure to import dist/server/importBuild.cjs
only in production. See Conditional manual import if your production and development share the same server entry file.
If you use vite.config.js
> build.outDir
then replace dist/server/importBuild.cjs
with ${build.outDir}/server/importBuild.cjs
.
See How it works if you're curious and/or you want to learn more.