Skip to content

[Bug][v9 Regression]: Storybook fail to run story with NextJs page that imports/renders MDX in CLI mode #31561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
CHC383 opened this issue May 23, 2025 · 3 comments

Comments

@CHC383
Copy link

CHC383 commented May 23, 2025

Describe the bug

In Storybook v9 (rc.4), stories using NextJs page that imports MDX as the testing component would fail to be run in CLI mode, which worked on Storybook v8.

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `MDXContent`.

Context:
This might be something related to import and export as mentioned in #5013 (comment). When NextJs pages which import MDX contents are imported by the stories (page.stories.tsx --> page.tsx --> doc.mdx), Storybook v9 has some problems to handle the MDX import in CLI mode, and the error above occurs. The same stories worked in Storybook browser mode and Storybook v8 (both browser mode and CLI mode).

The MDX page doesn't have an explicit export, so I think it is using default export handled by the MDX plugins.

Please check the reproduction link below for a minimal reproduction example, the tests passed on browser mode (pnpm storybook) but failed on CLI mode running through Vitest (pnpm test).

The branch storybook-v8 has the working version with storybook v8, specifically this is the diff between v8 and v9.

Reproduction link

https://github.com/CHC383/storybook-mdx-debug

Reproduction steps

  1. Checkout the code
  2. pnpm i
  3. pnpm test

System

Storybook Environment Info:

  System:
    OS: macOS 15.5
    CPU: (10) arm64 Apple M1 Pro
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.15.1 - ~/.asdf/installs/nodejs/22.15.1/bin/node
    npm: 10.9.2 - ~/.asdf/installs/nodejs/22.15.1/bin/npm
    pnpm: 10.11.0 - ~/.asdf/installs/nodejs/22.15.1/bin/pnpm <----- active
  Browsers:
    Chrome: 136.0.7103.114
    Safari: 18.5
  npmPackages:
    @storybook/addon-docs: ^9.0.0-rc.4 => 9.0.0-rc.4 
    @storybook/addon-vitest: 9.0.0-rc.4 => 9.0.0-rc.4 
    @storybook/nextjs-vite: 9.0.0-rc.4 => 9.0.0-rc.4 
    eslint-plugin-storybook: 9.0.0-rc.4 => 9.0.0-rc.4 
    storybook: ^9.0.0-rc.4 => 9.0.0-rc.4

Additional context

No response

@CHC383 CHC383 changed the title [Bug]: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object [Bug][v9]: Fail to import/render MDX May 24, 2025
@shilman
Copy link
Member

shilman commented May 25, 2025

Do you have addon-docs installed and listed in your .storybook/main.js addons?

@CHC383
Copy link
Author

CHC383 commented May 25, 2025

@shilman Yes I do, please see the reproduction link

@CHC383 CHC383 changed the title [Bug][v9]: Fail to import/render MDX [Bug][v9 Regression]: Storybook fail to run story with NextJs page that imports/renders MDX in CLI mode May 27, 2025
@shilman
Copy link
Member

shilman commented May 28, 2025

      storybookTest({
        storybookScript: 'pnpm storybook --ci',
        disableAddonDocs: false,
      }),

see #31457 for more info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants