-
-
Notifications
You must be signed in to change notification settings - Fork 19
rolldown-vite dev server fails to resolve CJS dependencies of a pre-compiled package #421
Description
Describe the bug
When using rolldown-vite for development, the dev server fails to correctly apply CommonJS-to-ESM transformations for dependencies that are nested inside another pre-compiled package (consumed via file: protocol or a tarball).
This results in the React.createElement: type is invalid error, because the CJS module is imported as an object with a default property, instead of being resolved to the component function itself.
Key Findings:
- The bug only occurs in the
devserver. A production build withpnpm buildsucceeds without errors. - The bug is specific to consuming a pre-compiled package. The issue is not reproducible when the packages are linked in a formal monorepo (e.g., using
pnpm-workspace.yaml), where the bundler has more context. - The bug does not occur with the standard Vite dev server.
This issue is critical for library authors who wish to use tsdown/rolldown and test their packages locally with pnpm pack or file: links before publishing.
Reproduction
https://github.com/ericskelton/rolldown-vite-cjs-dependency-repro
Steps to reproduce
1. Install Library Dependencies:
First, install the dependencies for the component library.
pnpm -C packages/react-library install2. Build the Component Library:
Next, build the react-library package. This step is crucial as it creates the dist directory that the react-app will link to.
pnpm -C packages/react-library build3. Install Application Dependencies:
Now that the library is built, install the dependencies for the React application. This will create a symlink to the compiled library files.
pnpm -C packages/react-app install4. Run the React Application:
Finally, start the react-app development server.
pnpm -C packages/react-app dev5. Observe the Bug:
- The application will open at
http://localhost:5173. - Navigate to Tab Two.
- The application will crash, and an
Element type is invaliderror will appear in the browser console.
System Info
npx envinfo --system --npmPackages '{vite,rolldown-vite,@vitejs/*,rollup,rolldown}' --binaries --browsers
System:
OS: Linux 5.15 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
CPU: (16) x64 Intel(R) Core(TM) Ultra 7 265H
Memory: 1.19 GB / 15.35 GB
Container: Yes
Shell: 5.2.21 - /bin/bash
Binaries:
Node: 24.6.0 - ~/.nvm/versions/node/v24.6.0/bin/node
Yarn: 1.22.22 - /mnt/c/Users/EricSkelton/AppData/Roaming/npm/yarn
npm: 11.5.1 - ~/.nvm/versions/node/v24.6.0/bin/npm
pnpm: 10.17.0 - ~/.local/share/pnpm/pnpm
Browsers:
Chrome: 138.0.7204.183Used Package Manager
pnpm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs and the Rolldown-related guide.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.