Skip to content
This repository was archived by the owner on Mar 19, 2026. It is now read-only.
This repository was archived by the owner on Mar 19, 2026. It is now read-only.

rolldown-vite dev server fails to resolve CJS dependencies of a pre-compiled package #421

@ericskelton

Description

@ericskelton

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 dev server. A production build with pnpm build succeeds 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 install

2. 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 build

3. 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 install

4. Run the React Application:
Finally, start the react-app development server.

pnpm -C packages/react-app dev

5. Observe the Bug:

  • The application will open at http://localhost:5173.
  • Navigate to Tab Two.
  • The application will crash, and an Element type is invalid error 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.183

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug: upstreamBug in a dependency of Vite

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions