question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Storybook Docs Vue: ReferenceError: "h is not defined"

See original GitHub issue

Describe the bug After upgrading Storybook to 5.3.0-rc.8 in my Vue application and try to migrate my stories to only MDX, the ‘Docs’ tab returns ReferenceError: "h is not defined"

To Reproduce Steps to reproduce the behavior:

  1. create an application using Vue;
  2. add @storybook/addon-docs@5.3.0-rc.8
  3. adjust main.js to load mdx files
stories: ['../src/components/**/*.stories.(js|mdx)'],
  1. Add MDX file: (any vue component) z-icon.stories.mdx
import { Meta, Story, Props } from '@storybook/addon-docs/blocks';
import { text, withKnobs } from '@storybook/addon-knobs';
import ZIcon from '../z-icon';

<Meta
  title='Icon'
  component={ZIcon}
  decorators={[withKnobs]}
/>

<Story name='normal'>
  {{
    components: {ZIcon},
    template: `<ZIcon :icon="['fab', 'cc-visa']" icon-size="larger"/>`,
  }}
</Story>

## Props

<Props of={ZIcon} />
  1. run npm run storybook;
  2. go to ‘Docs’ tab;
  3. see the error in console.

Expected behavior Docs works with MDX fully support in Vue.

Screenshots Captura de Tela 2020-01-03 às 14 49 51

Code snippets z-icon.stories.mdx generated when Storybook is running:

import React from 'react'
import { mdx } from '@mdx-js/react'

/* @jsx mdx */
import { assertIsFn, AddContext } from "@storybook/addon-docs/blocks";

import { Meta, Story, Props } from '@storybook/addon-docs/blocks';
import { text, withKnobs } from '@storybook/addon-knobs';
import ZIcon from '../z-icon';

const makeShortcode = name => function MDXDefaultShortcode(props) {
  console.warn("Component " + name + " was not imported, exported, or provided by MDXProvider as global scope")
  return <div {...props}/>
};

const layoutProps = {
  
};
const MDXLayout = "wrapper"
function MDXContent({
  components,
  ...props
}) {
  return <MDXLayout {...layoutProps} {...props} components={components} mdxType="MDXLayout">

    <Meta title='Icon' component={ZIcon} decorators={[withKnobs]} mdxType="Meta" />
    <Story name='normal' mdxType="Story">
  {{
        components: {
          ZIcon
        },
        template: `<ZIcon :icon="['fab', 'cc-visa']" icon-size="larger"/>`
      }}
    </Story>
    <h2 {...{
      "id": "props"
    }}>{`Props`}</h2>
    <Props of={ZIcon} mdxType="Props" />
    </MDXLayout>;
}

;
MDXContent.isMDXComponent = true;

export const normal = () => (
        {
  components: {
    ZIcon
  },
  template: `<ZIcon :icon="['fab', 'cc-visa']" icon-size="larger"/>`
}
      );
normal.story = {};
normal.story.name = 'normal';
normal.story.parameters = { mdxSource: '{\n  components: {\n    ZIcon\n  },\n  template: `<ZIcon :icon=\"[\'fab\', \'cc-visa\']\" icon-size=\"larger\"/>`\n}' };

const componentMeta = { title: 'Icon', decorators: [withKnobs], includeStories: ["normal"],  };

const mdxStoryNameToKey = {"normal":"normal"};

componentMeta.parameters = componentMeta.parameters || {};
componentMeta.parameters.docs = {
  ...(componentMeta.parameters.docs || {}),
  page: () => <AddContext mdxStoryNameToKey={mdxStoryNameToKey} mdxComponentMeta={componentMeta}><MDXContent /></AddContext>,
};

export default componentMeta;

System:

System:
    OS: macOS 10.15
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
  Binaries:
    Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
    Yarn: 1.19.0 - /usr/local/bin/yarn
    npm: 6.12.0 - ~/.nvm/versions/node/v10.15.3/bin/npm
  Browsers:
    Chrome: 79.0.3945.88
    Firefox: 71.0
    Safari: 13.0.2
  npmPackages:
    @storybook/addon-a11y: ^5.3.0-rc.8 => 5.3.0-rc.8
    @storybook/addon-actions: ^5.3.0-rc.8 => 5.3.0-rc.8
    @storybook/addon-docs: ^5.3.0-rc.8 => 5.3.0-rc.8
    @storybook/addon-knobs: ^5.3.0-rc.8 => 5.3.0-rc.8
    @storybook/addon-links: ^5.3.0-rc.8 => 5.3.0-rc.8
    @storybook/addon-storysource: ^5.3.0-rc.8 => 5.3.0-rc.8
    @storybook/addon-viewport: ^5.2.8 => 5.2.8
    @storybook/addons: ^5.3.0-rc.8 => 5.3.0-rc.8
    @storybook/cli: ^5.3.0-rc.8 => 5.3.0-rc.8
    @storybook/vue: ^5.3.0-rc.8 => 5.3.0-rc.8
  npmGlobalPackages:
    @storybook/cli: 5.3.0-rc.8

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
danilovazcommented, Jan 8, 2020

@Aaron-Pool You are absolutely right. In some of my tests I must have forgotten to set the Components property.

I really appreciate the support and patience from both of you.

Edited:

Now it’s works 🎉

1reaction
Aaron-Poolcommented, Jan 8, 2020

@danilovaz Yeah, so the problem here is that the content of each <Story> tag in MDX is itself a component. So, if you want to use a component locally, rather than globally registered, you need to register it in the story component with components: { ZCaption } (assuming you have imported the component in the file.

Or have you already tried that?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Vue] React Component => ReferenceError: h is not defined ...
I'm currently trying to get a Rect component working to display Icons, with an input to filter those Icons. And I looked around...
Read more >
What does h is not defined mean? - Stack Overflow
The author of storybook-addon-designs suggests the following: You have to replace the export const myStory = () => <Button>Hello, World!
Read more >
Frequently Asked Questions - Storybook - JS.ORG
I see ReferenceError: React is not defined when using Storybook with Next.js; How do I setup Storybook to share Webpack configuration with Next.js?...
Read more >
ReferenceError: "x" is not defined - JavaScript - MDN Web Docs
The JavaScript exception "variable is not defined" occurs when there is a non-existent variable referenced somewhere.
Read more >
require is not defined vite - You.com | The AI Search Engine ...
Vite JS / Vue 3 / SSR: ReferenceError window is not defined ... false" :open="open"> <div class="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found