-
-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
- Check if updating to the latest
preact-isoversion resolves the issue
Describe the bug
When building a client-side SPA that uses only preact-iso's routing features (Router, LocationProvider, Route), the build fails with Vite 8 (Rolldown) because preact-render-to-string is not installed.
To Reproduce
Reproduction repository: https://github.com/kazuma0129/preact-iso-vite8-repro
StackBlitz: https://stackblitz.com/github/kazuma0129/preact-iso-vite8-repro
Steps to reproduce:
- Clone the repository
- Run
npm install - Run
npm run build - See error:
Error: [vite]: Rolldown failed to resolve import "preact-render-to-string" from "node_modules/preact-iso/src/prerender.js".
This is most likely unintended because it can break your application at runtime.
Expected behavior
Build should succeed since the app only uses client-side routing features and does not use the prerender function.
Root Cause Analysis
preact-iso/src/index.jsexports aprerenderfunction via dynamic import:import('./prerender.js')- That
prerender.jsstatically importspreact-render-to-string - Vite 8 uses Rolldown which strictly resolves all imports including dynamic imports
- Since
preact-render-to-stringis not installed (not needed for client-side only apps), the build fails
Workaround
Add to vite.config.js:
export default defineConfig({
build: {
rolldownOptions: {
external: ['preact-render-to-string'],
},
},
});Suggested Fix
- Make
preact-render-to-stringan optional peerDependency - Or remove the
prerenderexport from the main entry point (preact-iso) and keep it only accessible via the subpathpreact-iso/prerender
Environment
- preact-iso: 2.11.1
- vite: 8.0.0
- Node.js: 22.x
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels