|
| 1 | +--- |
| 2 | +title: Fixing Storybook MDX runtime: “does not provide an export named 'ArgsTable'” |
| 3 | +description: "A minimal compatibility re-export in Storybook's blocks entry fixes an MDX runtime error caused by Vite pre-bundling renaming exports." |
| 4 | +tags: [Storybook, Vite, MDX, debugging, frontend] |
| 5 | +medium_tags: [Storybook, Vite, MDX, debugging, frontend] |
| 6 | +date: 2026-01-29 |
| 7 | +author: "wkylin" |
| 8 | +cover: /docs/static/images/storybook-argstable-cover-en.png |
| 9 | +og_image: /docs/static/images/storybook-argstable-cover-en.png |
| 10 | +canonical: "https://your-domain.example/blog/fix-storybook-argstable-en" |
| 11 | +--- |
| 12 | + |
| 13 | +# Fixing Storybook MDX runtime: “does not provide an export named 'ArgsTable'” — diagnosis, tests, and PR 🐞➡️✅ |
| 14 | + |
| 15 | +TL;DR: Vite pre-bundling can rename or remap named exports (e.g., `ArgsTable` → `PureArgsTable`) causing MDX imports to fail at runtime. I implemented a minimal compatibility re-export in the `blocks` entry and added tests; PR: https://github.com/storybookjs/storybook/pull/33702. |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## Background |
| 20 | + |
| 21 | +A Storybook MDX file importing `ArgsTable` from `@storybook/addon-docs/blocks` started failing at runtime with: |
| 22 | + |
| 23 | +> The requested module '.../blocks.js' does not provide an export named 'ArgsTable' |
| 24 | +
|
| 25 | +This error appeared in environments where Vite had pre-bundled dependencies (optimizeDeps), and the generated `blocks` module exposed `PureArgsTable` but not the named `ArgsTable`. |
| 26 | + |
| 27 | +## Investigation |
| 28 | + |
| 29 | +- Reproduced the runtime error locally while running Storybook with Vite. |
| 30 | +- Inspected the pre-bundled artifact in `.vite-cache/storybook/deps/` and confirmed `ArgsTable` missing and `PureArgsTable` present. |
| 31 | +- Considered two mitigation approaches: |
| 32 | + 1. Local shim + `optimizeDeps.exclude` workaround (short-term, used in our repo); |
| 33 | + 2. Upstream fix: ensure `blocks` exports the named symbol `ArgsTable`. |
| 34 | + |
| 35 | +## Implemented fix |
| 36 | + |
| 37 | +Minimal, non-breaking change to `code/addons/docs/src/blocks.ts`: |
| 38 | + |
| 39 | +```diff |
| 40 | +-export { ArgsTable as PureArgsTable } from './blocks/components/ArgsTable/ArgsTable'; |
| 41 | ++export { ArgsTable as PureArgsTable } from './blocks/components/ArgsTable/ArgsTable'; |
| 42 | ++// Compatibility re-export so `ArgsTable` remains available as a named export |
| 43 | ++export { ArgsTable } from './blocks/components/ArgsTable/ArgsTable'; |
| 44 | +``` |
| 45 | + |
| 46 | +Plus unit test at `code/addons/docs/src/__tests__/blocks.test.ts`: |
| 47 | + |
| 48 | +```ts |
| 49 | +import * as blocks from '../blocks'; |
| 50 | + |
| 51 | +describe('blocks module compatibility exports', () => { |
| 52 | + test('exports ArgsTable', () => expect(blocks.ArgsTable).toBeDefined()); |
| 53 | + test('ArgsTable equals PureArgsTable', () => expect(blocks.ArgsTable).toBe(blocks.PureArgsTable)); |
| 54 | +}); |
| 55 | +``` |
| 56 | + |
| 57 | +## How to verify locally |
| 58 | + |
| 59 | +- Run the added test: |
| 60 | + |
| 61 | +```bash |
| 62 | +npm run test:jest -- code/addons/docs/src/__tests__/blocks.test.ts |
| 63 | +``` |
| 64 | + |
| 65 | +- Start Storybook and verify MDX pages load normally: |
| 66 | + |
| 67 | +```bash |
| 68 | +npm run storybook |
| 69 | +# open http://localhost:6006 |
| 70 | +``` |
| 71 | + |
| 72 | +## Alternatives & notes |
| 73 | + |
| 74 | +- Short-term: local `ArgsTable` shim that renders explicit rows and adding `@storybook/addon-docs` to `optimizeDeps.exclude` to avoid the pre-bundling changes. |
| 75 | +- Long-term: adjust package `exports` map or build pipeline to guarantee stable named exports. |
| 76 | + |
| 77 | +## Links |
| 78 | + |
| 79 | +- Issue: https://github.com/storybookjs/storybook/issues/33691 |
| 80 | +- PR: https://github.com/storybookjs/storybook/pull/33702 |
| 81 | + |
| 82 | +--- |
| 83 | + |
| 84 | +## Screenshots & GIFs (suggestions and placeholders) 🖼️🎞️ |
| 85 | + |
| 86 | +Suggested assets to include in the post: |
| 87 | + |
| 88 | +- Cover image (Medium: recommended 1200×630px; Juejin: 900×500px), place as `docs/static/images/storybook-argstable-cover-en.png`. |
| 89 | +- Page screenshot: `docs/static/images/storybook-argstable-screenshot.png` (full page or key area). |
| 90 | +- Short GIF: `docs/static/images/storybook-argstable.gif` (3-5s clip). |
| 91 | + |
| 92 | +A `docs/static/images/README.md` is included with guidance and a small Playwright script to capture screenshots/videos automatically. |
| 93 | + |
| 94 | +## Detailed reproduction steps (step-by-step) 🧭 |
| 95 | + |
| 96 | +1. Remove Storybook Vite pre-bundle cache (to reproduce the pre-bundling behavior): |
| 97 | + |
| 98 | +```bash |
| 99 | +rm -rf .vite-cache/storybook |
| 100 | +``` |
| 101 | + |
| 102 | +2. Add a minimal MDX file that imports `ArgsTable`: |
| 103 | + |
| 104 | +```md |
| 105 | +--- |
| 106 | +name: ArgsTable demo |
| 107 | +--- |
| 108 | + |
| 109 | +import { ArgsTable } from '@storybook/addon-docs/blocks' |
| 110 | + |
| 111 | +# Demo |
| 112 | + |
| 113 | +<ArgsTable of={SomeComponent} /> |
| 114 | +``` |
| 115 | + |
| 116 | +3. Start Storybook and observe the runtime error: |
| 117 | + |
| 118 | +```bash |
| 119 | +npm run storybook |
| 120 | +``` |
| 121 | + |
| 122 | +You should see an error similar to: |
| 123 | + |
| 124 | +> The requested module '.../blocks.js' does not provide an export named 'ArgsTable' |
| 125 | +
|
| 126 | +4. Inspect the pre-bundled artifact to confirm the presence of `PureArgsTable` and absence of `ArgsTable`: |
| 127 | + |
| 128 | +```bash |
| 129 | +grep -n "PureArgsTable\|ArgsTable" .vite-cache/storybook/deps/* || true |
| 130 | +``` |
| 131 | + |
| 132 | +5. Run the added unit test to verify the fix: |
| 133 | + |
| 134 | +```bash |
| 135 | +npm run test:jest -- code/addons/docs/src/__tests__/blocks.test.ts |
| 136 | +``` |
| 137 | + |
| 138 | +## How to capture screenshots / generate GIFs (scripted) 🛠️ |
| 139 | + |
| 140 | +Use the included `scripts/capture-storybook.js` (Playwright) to: |
| 141 | + |
| 142 | +- navigate to a Storybook page and save `docs/static/images/storybook-argstable-screenshot.png`; |
| 143 | +- record a short webm to `docs/static/images/video/` (convert to GIF with ffmpeg if desired). |
| 144 | + |
| 145 | +Quick commands: |
| 146 | + |
| 147 | +```bash |
| 148 | +npm run storybook |
| 149 | +STORYBOOK_URL=http://localhost:6006 STORY_PATH='/?path=/story/your--story' node scripts/capture-storybook.js |
| 150 | +./scripts/convert-webm-to-gif.sh docs/static/images/video/latest.webm docs/static/images/storybook-argstable.gif |
| 151 | +``` |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +If you'd like, I can run the capture script locally and commit the images to the repo (I will need permission to run Storybook in your environment). |
0 commit comments