storybook: [Bug]: Unable to use Description without a Story in MDX

Describe the bug

An MDX (docs only) story with a Description errors with:

No primary story defined for docs entry. Did you forget to use `<Meta>`

To Reproduce

Create an MDX story file with Meta and a Description of a component:

import { Description, Meta } from "@storybook/addon-docs";
import { Button } from "./Button";

<Meta title="Button" />

<Description of={Button} />

Reproduction: https://github.com/will-stone/storybook-description-bug

System

Environment Info:

  System:
    OS: macOS 12.6.1
    CPU: (10) arm64 Apple M1 Max
  Binaries:
    Node: 16.18.1 - ~/.local/share/nvm/v16.18.1/bin/node
    npm: 8.19.2 - ~/.local/share/nvm/v16.18.1/bin/npm
  Browsers:
    Chrome: 107.0.5304.110
    Firefox: 107.0
    Safari: 16.1
  npmPackages:
    @storybook/addon-essentials: ^7.0.0-alpha.53 => 7.0.0-alpha.53
    @storybook/addon-interactions: ^7.0.0-alpha.53 => 7.0.0-alpha.53
    @storybook/addon-links: ^7.0.0-alpha.53 => 7.0.0-alpha.53
    @storybook/react: ^7.0.0-alpha.53 => 7.0.0-alpha.53
    @storybook/react-vite: ^7.0.0-alpha.53 => 7.0.0-alpha.53
    @storybook/testing-library: ^0.0.13 => 0.0.13

Additional context

This used to work (I last tested on alpha 48 but not sure which alpha between then and now was the one that changed). It is useful to be able to grab the JSDoc description of components/functions without having a Story. For example, we use this as a way to document our hooks and utility functions.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 6
  • Comments: 43 (16 by maintainers)

Commits related to this issue

Most upvoted comments

I browsed the docs for 7.0 and got an impression that it’s totally possible to use doc blocks in documentation-only mdx pages, but then run into this issue 😢 Would be a really useful feature, looking forward to it!

In 7.0.0-beta.8, I also have a similar error but this time related to the <Canvas> component. Based on the doc here, I should be able to use the folowing without issue.

import { Meta, Canvas } from '@storybook/addon-docs';

<Meta title="Documentation/Foundations/Color" />

<Canvas>
  <h2>Some here</h2>
</Canvas>

image

I’m running into this issue again with Canvas after upgrading to Storybook 8.

I’m just trying to wrap a piece of JSX in a Canvas inside a documentation-only MDX file. I’ve tried importing Canvas and Meta from @storybook/addon-docs and from @storybook/blocks (I tried all possible import combinations) but in all cases I get the same error: “No primary story defined for docs entry. Did you forget to use <Meta>?”. Same if I don’t use Meta at all and let the title be inferred from the first heading.

For someone still face the problem Did you forget to use <Meta>?, place Meta tag before other tags like Title, Primary 😂

Thanks for the update! I upgraded my project to beta.25 and it seems to have fixed Description. However I’m still seeing the original error for ArgsTable, Source, and Canvas. Are there plans to fix these components as well?

I’m having the same issue after upgrading to v8. Should this issue be reopened or should we raise a new one?

Seems to work fine for Title but not for Subtitle yet. Stacktrace still shows storyById is called from the Subtitle2 component.

import { Meta, Title, Subtitle } from '@storybook/blocks';

<Meta title='Introduction' />
<Title>Title test</Title>
<Subtitle>Sub title test</Subtitle>
Error: No primary story defined for docs entry. Did you forget to use `<Meta>`?

Thanks @mdaoust-sidlee, I’ve fixed it in #20803, should be released in the next couple of days.

@JReinhold using doc blocks in docs-only mdx files works great, the only caveat that i have run into is that you cannot import stories in .mdx docs-only files using the webpack aliases you defined in main.ts.

Something like this in a .mdx file:

import * as ComponentStories from '../../components/src/Component/Component.stories';

<Canvas of={ComponentStories.Default} />

will render correctly, while this:

import * as ComponentStories from '@components/Component/Component.stories';

<Canvas of={ComponentStories.Default} />

will fail with Invalid value passed to the 'of' prop. The value was resolved to a 'component or unknown' type but the only types for this block are: story

A little debug reveals that with the second scenario csfFiles passed to DocsContext is empty and then resolveOf throws.

The aliases itself are resolved because i can console.log in the mdx files the imported stories definitions, the problem is that exportsToCSFFile map is simply empty in DocsContext when using these aliases.

Did i run into some known limitation or is it a problem with my setup and you would need a reproduction from me?

@JReinhold yes. I looked into doing that first, but I wanted it to look the same as the actual canvases I used. And looking at the code, there’s quite a bit involved in getting the same style as the builtin blocks:

I guess what I really would want is a block that has this “preview” view, as just a simple styled component.

@JReinhold it’s mostly a visual thing. What we have currently is this:

## Sizes

<Canvas>
	<Story name="Large">
		<Button>Large button</Button>
	</Story>
	<Story name="Small">
		<Button size="small">Small button</Button>
	</Story>
</Canvas>

which renders as following:

image

While also producing 2 stories. I use the same pattern multiple places:

image

I mostly just care about the border/look of the Canvas, not the source and features like that - so I’d be completely OK with not using Canvas but something else. It would be even better if that “something” had unstyled set on it.

The last example I have is this:

<Canvas withSource="none">
	<Unstyled>
		<H1>H1 - Heading - Overskrift</H1>
		<H2>H2 - Form title - Skjematittel</H2>
		<H3>H3 - Section title - Grupperingstittel</H3>
		<H4>H4 - Form elements title - Tittel over skjemafelter</H4>
		<P>Txt - Body text - Brødtekst</P>
		<Span>Txt - Unstyled text</Span>
	</Unstyled>
</Canvas>

This more or less shows what I really want. The “look” of a canvas, with no storybook styling inside, and then showing multiple stories in that “box”. In this case:

image

I’d love to hear which use cases you have for having multiple stories in a single canvas

Showing all the variants of a small component (e.g. a button) in a summary view at the top of a document.

Did i run into some known limitation or is it a problem with my setup and you would need a reproduction from me?

The issue here will be that we need to interpret that import in the story indexer (which reads your MDX file statically). I’m not sure it is feasible for it to understand things like aliases. WDYT @shilman?

@JReinhold does that mean you can no longer do multiple stories in one canvas?

Still no luck with 7.0.0-beta.34. I still encounter the following error when I try to use the following mdx file :

import { Meta, Canvas } from '@storybook/addon-docs';

<Meta title="Documentation/Foundations/Color" />

<Canvas>
  <h2>Some here</h2>
</Canvas>

image

Ah yes that makes sense. Passing children to Canvas has been deprecated, moving forward you should use the of prop to reference a story. That also means that it can’t be used to wrap arbitrary content as before, but only to show a single story.

See the migration notes for more. The docs haven’t yet been updated to reflect this. https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#canvas-block

And your example is nether attached to stories with of on Meta or Canavs nor does it have any stories as children, so Canvas fails to find any stories.

With that said it should all be deprecations, and still support old behavior. Did this work in 6.5, a canvas without stories? Then we might have introduced a bug.

Still no luck with 7.0.0-beta.34. I still encounter the following error when I try to use the following mdx file :

import { Meta, Canvas } from '@storybook/addon-docs';

<Meta title="Documentation/Foundations/Color" />

<Canvas>
  <h2>Some here</h2>
</Canvas>

image

Ahh, so are you using <Source code="..." /> in an unattached docs file (i.e plain .mdx file) @dryton? I think this is a bug for sure, I’ll open a new ticket for it.

We’ve finished migrating all the blocks to the new API, so this should be fixed.

We’ve changed the API for many of the blocks (with deprecation warnings), we’re not ready with the new docs for them, but in the mean time you can check the migration notes which should give a sense of the changes.

Whoopee!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.0-beta.25 containing PR #20563 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb@next upgrade --prerelease

Closing this issue. Please re-open if you think there’s still more to do.

Don’t know if my issue is related, but I’ll add it here too.


After upgrading to Storybook 7 I am noticing that my docs-only pages are no longer working if they have Story objects in them.

In our application we have 3 basic pages to describe the use of typography, icons and color. all of these pages work fine if I remove any Story-blocks, if story-blocks are defined then the page raises the following error:

No primary story defined for docs entry. Did you forget to use `<Meta>`?

I have tried using the Story and Canvas components from 2 different places, both without success:

import { Meta, Story, Typeset, Canvas } from '@storybook/addon-docs';
import '~components/App/app.scss';

<Meta title="StyleGuide/Typography" />

...text content here...

## Header 1
<Canvas>
  <Story id="atoms-headers--header-one" />
</Canvas>
import { Meta, Title, IconGallery, IconItem } from '@storybook/addon-docs';
import { Story, Canvas } from '@storybook/blocks'
import '~components/App/app.scss';

<Meta title="StyleGuide/Iconography" />

...text content here...

### Loading (default)
<Canvas>
  <Story id="atoms-loading--default-loading" />
</Canvas>

Rendering the components without a story (so <Loading /> seems to work fine for now so I’ll fallback to that)

System specifications:

 System:
    OS: macOS 13.0
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 18.11.0 - /usr/local/bin/node
    Yarn: 3.2.2 - /REDACTED/node_modules/.bin/yarn
    npm: 8.19.2 - /usr/local/bin/npm
  Browsers:
    Chrome: 108.0.5359.71
    Firefox: 107.0
    Safari: 16.1
  npmPackages:
    @storybook/addon-actions: ^7.0.0-alpha.54 => 7.0.0-alpha.54
    @storybook/addon-essentials: ^7.0.0-alpha.54 => 7.0.0-alpha.54
    @storybook/addon-interactions: ^7.0.0-alpha.54 => 7.0.0-alpha.54
    @storybook/addon-links: ^7.0.0-alpha.54 => 7.0.0-alpha.54
    @storybook/node-logger: ^7.0.0-alpha.54 => 7.0.0-alpha.54
    @storybook/preset-create-react-app: ^4.1.2 => 4.1.2
    @storybook/react: ^7.0.0-alpha.54 => 7.0.0-alpha.54
    @storybook/react-webpack5: ^7.0.0-alpha.54 => 7.0.0-alpha.54