Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Next.js and React

Storybook cannot index Introduction.stories.mdx after an upgrade

Your error

Unable to index ./src/stories/Introduction.stories.mdx2 more lines it can show

Fix it fast

Most common cause, 1 of 2

The file still uses the removed .stories.mdx format

If the file only holds documentation and no story exports, drop the .stories part of the name.

Fix
git mv src/stories/Introduction.stories.mdx src/stories/Introduction.mdx

// .storybook/main.ts
stories: [
  '../src/**/*.mdx',
  '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)',
],

// Button.mdx, attached to Button.stories.tsx (import path for Storybook 9 and 10)
import { Canvas, Meta } from '@storybook/addon-docs/blocks';
import * as ButtonStories from './Button.stories';

<Meta of={ButtonStories} />
<Canvas of={ButtonStories.Primary} />
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Unable to index ./src/stories/Introduction.stories.mdx appears because Storybook 8 removed the .stories.mdx format, and Storybook 9 and 10 kept it out. The indexer parses such a file as a story file and fails. Rename a docs-only page to .mdx, move real stories into a CSF file, list .mdx in the stories glob, then fix any MDX 3 syntax errors.

  • Applies to Storybook 8, Storybook 9, Storybook 10.6, Node.js 24
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

List every .stories.mdx file and look at the stories globs. A file whose name ends in .stories.mdx is the first suspect, whatever the error says after the path.

Run this first
find . -name "*.stories.mdx" -not -path "./node_modules/*"
grep -n -A6 "stories" .storybook/main.*

Then find the line you see in this list and open its fix:

  1. 1The file still uses the removed .stories.mdx formatThe path in the error ends in .stories.mdx, and the project was upgraded from Storybook 7 or older (or created from an old template)
  2. 2The renamed .mdx file contains syntax that MDX 3 rejectsThe log adds the line about an MDX2 syntax error, or the error names a line in the .mdx file

What does the error look like?

  • Unable to index ./src/stories/Introduction.stories.mdx
  • Unable to index files:
  • This seems to be an MDX2 syntax error. Please refer to the MDX section in the following resource for assistance on how to fix this

Cause 1 of 2

The file still uses the removed .stories.mdx format

You seeThe path in the error ends in .stories.mdx, and the project was upgraded from Storybook 7 or older (or created from an old template)

Check

Unable to index on a file that ends in .stories.mdx means the file still uses the CSF-in-MDX format that Storybook 8 removed. The Storybook 8 migration notes say that .stories.mdx files are no longer supported. In the indexer's own source, an .mdx file counts as a docs page only when its name does not end in .stories, so the file is parsed as a story file instead.

Check
grep -n "Meta\|Story\|Canvas" src/stories/Introduction.stories.mdx

Fix

If the file only holds documentation and no story exports, drop the .stories part of the name. If it also defines stories, move those into a CSF file next to it and attach an .mdx page to that file with Meta and the of prop. Then make sure the stories glob lists .mdx files.

Fix
git mv src/stories/Introduction.stories.mdx src/stories/Introduction.mdx

// .storybook/main.ts
stories: [
  '../src/**/*.mdx',
  '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)',
],

// Button.mdx, attached to Button.stories.tsx (import path for Storybook 9 and 10)
import { Canvas, Meta } from '@storybook/addon-docs/blocks';
import * as ButtonStories from './Button.stories';

<Meta of={ButtonStories} />
<Canvas of={ButtonStories.Primary} />

Verify

Restart Storybook. The sidebar shows the docs page and the terminal no longer prints Unable to index for that file.

Verify
npm run storybook

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 2

The renamed .mdx file contains syntax that MDX 3 rejects

You seeThe log adds the line about an MDX2 syntax error, or the error names a line in the .mdx file

Check

Unable to index on a renamed .mdx page, with the MDX2 syntax hint, points to markup that MDX 3 refuses. Storybook 8 and newer compile docs with MDX 3, which is stricter than the MDX 1 that old pages were written for. MDX does not accept HTML comments, and a bare < or { in running text must be escaped. The grep below finds the comments; a stray bracket shows up in the line the error names. Storybook 7's notes describe an automigration, mdx1to2, that rewrote MDX 1 HTML comments as JSX comments, and files that never went through it still hold the old form.

Check
grep -rn "<!--" src .storybook --include='*.mdx'

Fix

MDX's own guide says to use JavaScript comments in braces instead of HTML comments, and to escape a left angle bracket or a left curly brace with a backslash when you mean the character itself.

Fix
{/* a comment that MDX accepts */}

Use \{ and \< when you mean the characters themselves.

Verify

Restart Storybook and open the docs page. The MDX syntax warning is gone.

Verify
npm run storybook

Confirmed by mdxjs.com

Did this fix it?

How do I stop it coming back?

  • Name docs-only pages Something.mdx and keep story definitions in .stories.tsx or .stories.ts files.
  • Read the migration notes for every major Storybook version before you move to it, and search the project for each removed API they list.
  • Write comments in MDX as JSX comments from the start.
  • Build Storybook in CI, so an indexing error fails the pipeline instead of showing up on a colleague's machine.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, Workforce.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.