Skip to content

optimizeDeps: circular chunk dependency causes TDZ error with molstar (regression in beta.13 / rolldown rc.3) #597

@pechersky

Description

@pechersky

Describe the bug

vite@8.0.0-beta.13 (rolldown 1.0.0-rc.3) introduced a regression where optimizeDeps produces chunks with circular imports that cause runtime errors. Works fine on 8.0.0-beta.11 (rolldown 1.0.0-rc.2).

Expected behavior
Chunks produced by optimizeDeps should not have circular imports that break top-level initialization, or the shared chunk should contain the entry chunk's code to avoid the cycle.

Browser console:

Uncaught TypeError: Cannot read properties of undefined (reading 'MappedStatic')
    at getSecondaryStructureParams (molstar_lib_mol-model-props_computed_secondary-structure__js.js:10:33)

The optimized output has this circular structure:

zhang-skolnik-*.js (shared)  ──imports──>  secondary-structure.js (entry)
         ^                                          │
         └──────────────imports─────────────────────┘

Workaround doesn't work, causes cascading CJS issues

optimizeDeps: {
  exclude: ["molstar"],
}

Reproduction

https://stackblitz.com/edit/vitejs-vite-3yh26fyo?file=vite.config.ts

Steps to reproduce

No response

System Info

System:
    OS: Linux 5.15 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12800H
    Memory: 10.02 GB / 31.19 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 24.3.0 - /run/user/1000/fnm_multishells/715052_1770846790025/bin/node
    npm: 11.8.0 - /run/user/1000/fnm_multishells/715052_1770846790025/bin/npm
    pnpm: 9.12.3 - /home/yakov/.local/share/pnpm/pnpm
  Browsers:
    Chrome: 144.0.7559.132
  npmPackages:
    @vitejs/plugin-react: ^5.1.3 => 5.1.3

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions