Skip to content

Storybook globals don't exist in rolldown-vite-based build #562

@bengry

Description

@bengry

Describe the bug

When using rolldown-vite with Storybook v10 and @storybook/addon-docs, the built Storybook fails at runtime with ReferenceError: __STORYBOOK_MODULE_*__ is not defined.

What I expect: Built Storybook loads without errors, same as with standard Vite.

What actually happens: Console errors on page load:

Uncaught ReferenceError: __STORYBOOK_MODULE_CORE_EVENTS_PREVIEW_ERRORS__ is not defined
    at csf-BrJoaeT2.js:4:13387

or

Uncaught ReferenceError: __STORYBOOK_MODULE_CLIENT_LOGGER__ is not defined
    at instrumenter-LwmSDSR-.js:48:53

Observations:

  • Only affects built Storybook (dev mode works fine)
  • Only happens when @storybook/addon-docs is enabled (other addons work fine). Might not be related to this addon speicifically, since another smaller repo with it works, but I guess it happens in some cases due to chunking/code splitting.
  • Standard Vite does NOT have this issue - only rolldown-vite
  • I noticed a csf-*.js chunk (~149KB) appears in rolldown-vite builds but not in standard Vite builds - this might be related to differences in code splitting behavior

Reproduction

https://github.com/bengry/rolldown-vite-storybook-globals-bug

Steps to reproduce

  1. Clone the repo and install:

    git clone https://github.com/bengry/rolldown-vite-storybook-globals-bug
    cd rolldown-vite-storybook-globals-bug
    yarn install
  2. Build Storybook:

    yarn build-storybook
  3. Serve the built output:

    npx serve ./apps/storybook/storybook-static
  4. Open browser and check devtools console - you'll see the ReferenceError

System Info

System:
  OS: macOS 26.1
  CPU: (16) arm64 Apple M3 Max
  Memory: 494.23 MB / 64.00 GB
  Shell: 4.2.1 - /opt/homebrew/bin/fish
Binaries:
  Node: 24.10.0
  Yarn: 4.12.0
  npm: 11.7.0
Browsers:
  Chrome: 143.0.7499.110
  Safari: 26.1
npmPackages:
  @vitejs/plugin-react: ^5.1.2 => 5.1.2 
  rolldown-vite: 7.2.11

Used Package Manager

yarn

Logs

Click to expand!
# Build output shows csf chunk:
storybook-static/assets/csf-BrJoaeT2.js   149.02 kB │ gzip: 46.82 kB

# Browser console error:
Uncaught ReferenceError: __STORYBOOK_MODULE_CORE_EVENTS_PREVIEW_ERRORS__ is not defined
    at csf-BrJoaeT2.js:4:13387

Validations

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