-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Addon-docs: Simplest MDX not working @vue/cli app #8096
Comments
@Aaron-Pool any idea what's going on here? |
Looks like the Vue babel preset is trying to run on @margielm, make sure that whatever Babel config is including the Vue preset isn't running on MDX files. The docs preset should be sufficient to handle transpiring the MDX files. If you could post your |
I'm experiencing the same issue. vue.config.js const sharedConf = require('./config/shared-webpack-conf')
module.exports = {
productionSourceMap: false,
lintOnSave: true,
pluginOptions: {
stylelint: {
formatter: () => require('prettier'),
},
'style-resources-loader': sharedConf.styleResourcesLoaderOptions,
},
css: {
extract: true,
},
configureWebpack: {
resolve: {
alias: sharedConf.aliases,
},
},
} babel.config.js module.exports = (api) => {
api.cache(true)
return {
presets: ['@vue/app', '@babel/preset-env'],
plugins: ['transform-vue-jsx', '@babel/plugin-transform-runtime'],
}
} |
@alexkcollier, you have a lot of duplicate things in your Babel config, And, like I said to @margielm, make sure that no Vue loaders are running on |
If either of you are still having problems, and can setup a minimal repo that I can debug with your configuration, I would be happy to! |
I did that in my original request. |
@margielm my apologies. I'm what some people would call "an idiot" 😬 I'll check it out ASAP. |
No worries, it happens 😄 I am super glad that it is moving forward. Thank you! |
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. |
If you are not actually using JSX in Vue, the @vue/app preset makes it easy to disable as a workaround: module.exports = {
presets: [
[
'@vue/app',
{
/* Disabled due to clash between core-js versions in Storybook / Vue CLI */
useBuiltIns: false,
/* Disabled due to clash with Storybook MDX */
jsx: false
}
]
]
} |
@raihle this is great intel, thanks for the tip! |
@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. |
Unfortunately, I am the one use jsx in vue 😭 |
@jeffwcx I use JSX in my storybook project as well, and we're definitely set on getting it working. Stay tuned. |
I had the same error, so I tried to disable JSX in the Vue babel preset, but then it's not able to parse the JSX in my Storybook config file to setup the inline rendering: prepareForInline: storyFn => {
const Story = toReact(storyFn());
return <Story />;
}, It throws:
The Docs preset cause other issues with Prettier, that's why I went for the manual setup instead of the Docs preset. Any idea what's missing for Storybook to handle JSX in the config file? Or how I could rewrite the statement above without JSX at all? |
@LeBenLeBen Try |
@shilman Perfect, it works fine, thank you! |
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 |
@trevoreyre This is a great temp work-around. It does seem however, for me at least, to break Jest unit tests as without a Just wondering if anyone brighter than me, not hard, had any suggestions? |
As a point for consideration, I would greatly appreciate if the working setup/config could be packaged up as a vue cli plugin (with perhaps a pre-made .stories file to go along with the default HelloWorld.vue component) |
@andywd7 I think you can configure environment specific settings in your Babel config. If you confine the changes in the work around to environments that aren't "test", I think that may work? |
So, I worked on this yesterday and debugged the following. In default Vue App serving storybook with the following in Default addons: [
{
name: '@storybook/addon-docs',
}
] results in the following error while viewing docs
will give the following webpack config /\.(stories|story).mdx$/
{
"test": {},
"use": [
{
"loader": "babel-loader",
"options": {
"cacheDirectory": "/Users/pksunkara/Coding/storybooks/docs/node_modules/.cache/storybook",
"presets": [
[
"/Users/pksunkara/Coding/storybooks/docs/node_modules/@babel/preset-env/lib/index.js",
{
"shippedProposals": true,
"useBuiltIns": "usage",
"corejs": "3"
}
]
],
"plugins": [
"/Users/pksunkara/Coding/storybooks/docs/node_modules/@babel/plugin-proposal-object-rest-spread/lib/index.js",
"/Users/pksunkara/Coding/storybooks/docs/node_modules/@babel/plugin-proposal-class-properties/lib/index.js",
"/Users/pksunkara/Coding/storybooks/docs/node_modules/@babel/plugin-syntax-dynamic-import/lib/index.js",
[
"/Users/pksunkara/Coding/storybooks/docs/node_modules/babel-plugin-emotion/dist/babel-plugin-emotion.cjs.js",
{
"sourceMap": true,
"autoLabel": true
}
],
"/Users/pksunkara/Coding/storybooks/docs/node_modules/babel-plugin-macros/dist/index.js",
"@babel/plugin-transform-react-jsx"
]
}
},
{
"loader": "@mdx-js/loader",
"options": {
"compilers": [
null
]
}
}
]
} With Options addons: [
{
name: '@storybook/addon-docs',
options: {
babelOptions: {
presets: [
[
'@vue/cli-plugin-babel/preset',
{
jsx: false
}
]
]
}
}
}
] works perfectly showing the docs with the following webpack config /\.(stories|story).mdx$/
{
"test": {},
"use": [
{
"loader": "babel-loader",
"options": {
"presets": [
[
"@vue/cli-plugin-babel/preset",
{
"jsx": false
}
]
],
"plugins": [
"@babel/plugin-transform-react-jsx"
]
}
},
{
"loader": "@mdx-js/loader",
"options": {
"compilers": [
null
]
}
}
]
} /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. |
Has anyone found a reliable fix for this? I've managed to get the Docs tab to render without error, but it doesn't actually render my component, just the text that would be the label for the button. ui-button.vue
babel.config.js
ui-button.stories.mdx
Docs tab HTML
Any help would be much appreciated. We'd love to use Storybook for our project, but really do require |
I'm using the latest version of vue-cli-plugin-storybook in multiple projects and it works fine with docs. |
@LeBenLeBen With docs, or with Also, could you please share your config so we can see if there's any diff between our configs and yours? If you've got it working, then I'm sure a lot of people would love to take a look at how. Also, can you provide the semver of what you mean by "latest version of the |
@AJB99 is <Story name="ui-button-story">
{{
components: { uiButton },
template : '<ui-button>Click Me</ui-button>',
}}
</Story> The component attribute of the |
You can check out this repo that has a Vue CLI using the plugin for Storybook (under packages/chusho). It doesn't have any In any case I think @Aaron-Pool is right and you should ensure your component is available for usage first. |
Crikey!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.0.0-beta.29 containing PR #11185 that references this issue. Upgrade today to try it out! You can find this prerelease on the Closing this issue. Please re-open if you think there's still more to do. |
Olé!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.0.0-rc.2 containing PR #11495 that references this issue. Upgrade today to try it out! You can find this prerelease on the |
Describe the bug
After upgrading to [email protected] and adding MDX support to a Vue application created with @Vue/cli - the doc tab is is throwing following error:
To Reproduce
Steps to reproduce the behavior:
@storybook/addon-docs
->yarn add @storybook/[email protected] --dev
addons.js
addon-docs
presets inpresets.js
mdx
filesAddon|Docs/test
story and go toDocs
tabExpected 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(R) Core(TM) 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
The text was updated successfully, but these errors were encountered: