Skip to content

[Bug]: Dep optimizer: CJS init function not called before exported function in pre-bundled chunks #8950

@dagda1

Description

@dagda1

Reproduction link or steps

Setup

Clone this repo

git clone https://github.com/dagda1/rolldown-mui-repro.git
pnpm install
pnpm build
pnpm start:frontend

Open the browser URL shown in the terminal http://localhost:3400/. The console will show:

Uncaught TypeError: Cannot read properties of undefined (reading 'muiName')

What is expected?

init_createSvgIcon should be called before createSvgIcon is available to consumers, ensuring SvgIcon is initialized.

What is actually happening?

The dep optimizer pre-bundles @mui/material into a shared chunk (utils-*.js). This chunk contains both createSvgIcon and its init function init_createSvgIcon.

The icon entry file (@mui_icons-material_KeyboardArrowDown.js) imports createSvgIcon and calls it immediately at module scope — but never imports or calls init_createSvgIcon. So SvgIcon is still undefined when createSvgIcon accesses SvgIcon.muiName.

System Info

System:
    OS: macOS 26.3.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 3.98 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 25.8.2 - /opt/homebrew/bin/node
    Yarn: 4.0.0 - /Users/paulcowan/.volta/bin/yarn
    npm: 11.11.1 - /opt/homebrew/bin/npm
    pnpm: 10.33.0 - /Users/paulcowan/.volta/bin/pnpm
    Deno: 2.2.1 - /Users/paulcowan/.deno/bin/deno
  Browsers:
    Chrome: 146.0.7680.165
    Firefox: 122.0.1
    Safari: 26.3.1

Any additional comments?

This worked until upgrading from vite 7 to vite 8

Metadata

Metadata

Type

Priority

None yet

Effort

None yet

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions