cloudflare / cloudflare/workers-sdk

[vite-plugin] Storybook startup fails during Worker export inspection in middleware mode

Open
#14,979 1 comment 0 reactions 0 assignees View on GitHub
package:vite-plugin
Dominant language
TypeScript
Stars
4.5k
Forks
1.5k
Avg merge
2d 21h
Merged PRs (30d)
183

Description

### What versions & operating system are you using?

System:
OS: macOS 26.5.2 (arm64)
Node: 24.13.0
pnpm: 11.7.0

Packages:
@cloudflare/vite-plugin: 1.49.0
wrangler: 4.116.0
vite: 8.2.0
storybook: 10.5.5
@storybook/tanstack-react: 10.5.5
@tanstack/react-start: 1.168.34

### Please provide a link to a minimal reproduction

https://github.com/ssj9685/storybook-cloudflare-vite-repro

### Describe the Bug

Storybook fails to start in a TanStack Start app configured for Cloudflare Workers.

Steps to reproduce:

1. `pnpm install`
2. `pnpm run storybook`

Expected: Storybook starts.

Actual: Storybook fails before rendering any story.

The application Worker does not import Storybook. During startup, `@storybook/tanstack-react` intercepts `virtual:cloudflare/worker-entry` and resolves it to a mock that imports `storybook/test`. The Cloudflare Vite plugin then evaluates that transformed entry in `getWorkerEntryExportTypes`, where Storybook's externalized global is unavailable.

Changing only the Storybook framework to `@storybook/react-vite` allows Storybook to start with the same Vite configuration.

Related: #8892, #9108, and draft PR #14551.

### Please provide any relevant error logs

```text
=> Failed to build the preview
ReferenceError: __STORYBOOK_MODULE_TEST__ is not defined
at runInRunnerObject (workers/runner-worker/index.js:107:3)
at getWorkerEntryExportTypes (workers/runner-worker/index.js:251:29)
```

Contributor guide

Open the contributing guide

Research direction

Start with the minimal reproduction and run pnpm install followed by pnpm run storybook. Trace the virtual:cloudflare/worker-entry interception into getWorkerEntryExportTypes and compare it with the @storybook/react-vite configuration. Done means the TanStack Start app's Storybook preview starts without the __STORYBOOK_MODULE_TEST__ ReferenceError.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vite
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.