Skip to content

MDX stories named with a pattern other than *.stories.mdx don't compile correctly #9918

@stevesims

Description

@stevesims

Describe the bug
I decided that I'd name my storybook files stories.mdx (and have them sit in a directory besides index and test files). Unfortunately doing so results in storybook failing, showing an error that reads Unexpected default export without title: undefined

To Reproduce
Steps to reproduce the behavior:

In .storybook/main.js set up the search path for stories to look for differently named files - in my case this was:

  stories: ['../src/**/(*.stories|stories).(ts|tsx|js|mdx)'],

Then make sure you have a valid stories file named stories.mdx.

Restart storybook and you'll see an error.

(You can try other naming formats too - I've tried replacing stories with a different word, for example, so it would match *.testword.mdx and that results in an identical error.)

Looking at the transpiled output of the mdx files from sources panel in Chrome inspector I can see that the output of a file that is not named following the *.stories.mdx pattern omits everything beyond a line reading MDXContent.isMDXComponent = true; compared to working stories. (An import of assertIsFn and AddContext is also omitted). It is this omission of that code that causes the crash.

It would therefore seem that the transpilation is incomplete.

Expected behavior
The pattern given above should match files following the pattern of both *.stories.mdx and plain stories.mdx, which it does. One would expect mdx stories to be transpiled correctly given the configuration.

Screenshots
If applicable, add screenshots to help explain your problem.

Code snippets
If applicable, add code samples to help explain your problem.

System:

Environment Info:

  System:
    OS: macOS Mojave 10.14.4
    CPU: (4) x64 Intel(R) Core(TM) i5-8210Y CPU @ 1.60GHz
  Binaries:
    Node: 10.16.3 - ~/.nvm/versions/node/v10.16.3/bin/node
    Yarn: 1.22.0 - /usr/local/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v10.16.3/bin/npm
  Browsers:
    Firefox: 72.0.2
    Safari: 12.1
  npmPackages:
    @storybook/addon-docs: ^5.3.13 => 5.3.13 
    @storybook/addons: ^5.3.13 => 5.3.13 
    @storybook/react: ^5.3.13 => 5.3.13 
    @storybook/storybook-deployer: ^2.8.1 => 2.8.1 

Additional context
Given the configuration above, as my path matching maintains support for the *.stories.mdx pattern if I rename a file from stories.mdx to 0.stories.mdx then it will compile correctly and the error goes away.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions