storybook: Addon-docs: Simplest MDX not working @vue/cli app
Describe the bug After upgrading to storybook@5.2 and adding MDX support to a Vue application created with @Vue/cli - the doc tab is is throwing following error:
h is not defined
ReferenceError: h is not defined
at container (http://localhost:6006/main.831d3d75a097f0e9391d.bundle.js:667:5)
at renderWithHooks (http://localhost:6006/vendors~main.831d3d75a097f0e9391d.bundle.js:83540:18)
at mountIndeterminateComponent (http://localhost:6006/vendors~main.831d3d75a097f0e9391d.bundle.js:85774:13)
at beginWork$1 (http://localhost:6006/vendors~main.831d3d75a097f0e9391d.bundle.js:86918:16)
at HTMLUnknownElement.callCallback (http://localhost:6006/vendors~main.831d3d75a097f0e9391d.bundle.js:68779:14)
at Object.invokeGuardedCallbackDev (http://localhost:6006/vendors~main.831d3d75a097f0e9391d.bundle.js:68829:16)
at invokeGuardedCallback (http://localhost:6006/vendors~main.831d3d75a097f0e9391d.bundle.js:68886:31)
at beginWork$$1 (http://localhost:6006/vendors~main.831d3d75a097f0e9391d.bundle.js:91649:7)
at performUnitOfWork (http://localhost:6006/vendors~main.831d3d75a097f0e9391d.bundle.js:90640:12)
at workLoopSync (http://localhost:6006/vendors~main.831d3d75a097f0e9391d.bundle.js:90617:22)
To Reproduce Steps to reproduce the behavior:
- create an application using @vue/cli
- initalize storybook with
- add
@storybook/addon-docs
->yarn add @storybook/addon-docs@5.2 --dev
- register addon in
addons.js
- register
addon-docs
presets inpresets.js
- adjust config.js to load
mdx
files - Add simple MDX file:
import { Story, Meta } from '@storybook/addon-docs/blocks';
<Meta title="Addon|Docs" />
<Story name="test">
{{
template: '<div>Hello World</div>',
}}
</Story>
- start storybook
- click on
Addon|Docs/test
story and go toDocs
tab - see the error
Expected behavior To see the documentation page
Screenshots
Code snippets https://github.com/margielm/sb-test https://github.com/margielm/sb-test/blob/master/stories/hello.stories.mdx
System: System: OS: macOS 10.14.6 CPU: (8) x64 Intel® Core™ i7-4770HQ CPU @ 2.20GHz Binaries: Node: 12.10.0 - /usr/local/bin/node Yarn: 1.17.3 - /usr/local/bin/yarn npm: 6.11.3 - /usr/local/bin/npm Browsers: Chrome: 76.0.3809.132 Firefox: 67.0 Safari: 12.1.2 npmPackages: @storybook/addon-actions: ^5.2.0 => 5.2.0 @storybook/addon-docs: 5.2.0 => 5.2.0 @storybook/addon-links: ^5.2.0 => 5.2.0 @storybook/addons: ^5.2.0 => 5.2.0 @storybook/vue: ^5.2.0 => 5.2.0
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 29 (20 by maintainers)
If you are not actually using JSX in Vue, the @vue/app preset makes it easy to disable as a workaround:
So, I worked on this yesterday and debugged the following.
In default Vue App serving storybook with the following in
main.js
Default
results in the following error while viewing docs
will give the following webpack config
With Options
works perfectly showing the docs with the following webpack config
/cc @shilman @Aaron-Pool
So, the first question we can ask is, why is by default stories not taking babel config from babel.config.js. If it needs some stuff to work (babel-emotion), then why is it working correctly even though we removed them when passing babelOptions.
I did that in my original request. Repo is here: https://github.com/margielm/sb-test. And the MDX file is here: https://github.com/margielm/sb-test/blob/master/stories/hello.stories.mdx . If we want to spread the usage of Storybook for maximum extend, and we do because it is wonderful tool 😃, we need to make it a as simple as possible to setup for applications created with CLI. That applies not only to React or Vue, but also Angular, and others.
@margielm my apologies. I’m what some people would call “an idiot” 😬
I’ll check it out ASAP.
@AJB99 is
ui-button
declared globally? If not, you need to add it to your story component definition, like:The component attribute of the
Meta
tag is used by storybook to generate documentation automatically, whereas the contents of theStory
block is just a Vue component definition that knows nothing about the rest of the file.I’m using the latest version of vue-cli-plugin-storybook in multiple projects and it works fine with docs.
As a temporary work-around, I was able to tweak the Storybook webpack config to get MDX stories working for Vue components without having to disable JSX. Many thanks to @Aaron-Pool for helping me debug. I set up an example repo here:
https://github.com/trevoreyre/storybook-mdx-vue-example
@raihle thanks! That was an oversight on my part, and I definitely should have mentioned that. I use JSX pretty commonly, and I tend to forget that a large portion (probably even the majority) of the Vue user base doesn’t need that part of the Babel preset at all.
@LeBenLeBen Try
return React.createElement(Story)
?@raihle this is great intel, thanks for the tip!
So, it looks like this is indeed an issue with competing jsx loaders. The Vue jsx plugins are processing nthe MDX before the react plugin gets a chance to. And Vue jsx isn’t valid in MDX content format yet. I’ll try to chat with @shilman about the best way to get this fixed.
@alexkcollier, you have a lot of duplicate things in your Babel config,
@vue/app
is a super set of@babel/preset-env
. So you should get rid of preset-env. Additionally, the@vue/app
preset contains the@vue/jsx
preset, so you should be able to remove thetransform-vue-jsx
plugin as well.And, like I said to @margielm, make sure that no Vue loaders are running on
mdx
files. The only loaders running onmdx
file types should be provided by the docs preset. If you let the Vue preset run onmdx
files, the react and Vue jsx plugins will interfere with one another.