Skip to content

Build fails with Vite 8 (Rolldown): cannot resolve preact-render-to-string #136

@kazuma0129

Description

@kazuma0129
  • Check if updating to the latest preact-iso version 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:

  1. Clone the repository
  2. Run npm install
  3. Run npm run build
  4. 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.js exports a prerender function via dynamic import: import('./prerender.js')
  • That prerender.js statically imports preact-render-to-string
  • Vite 8 uses Rolldown which strictly resolves all imports including dynamic imports
  • Since preact-render-to-string is 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

  1. Make preact-render-to-string an optional peerDependency
  2. Or remove the prerender export from the main entry point (preact-iso) and keep it only accessible via the subpath preact-iso/prerender

Environment

  • preact-iso: 2.11.1
  • vite: 8.0.0
  • Node.js: 22.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions