storybook: Module build failed with MDX files: Unexpected token
Describe the bug My mdx files fail after upgrade to Storybook version 5.3.14. In Storybook 5.3.9 everything works fine. I have no empty lines in my MDX files.
WARNING in ./src/****/Test.mdx
Module build failed (from ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js):
SyntaxError: /src/****/Test.mdx: Unexpected token (13:9)
11 | const makeShortcode = name => function MDXDefaultShortcode(props) {
12 | console.warn("Component " + name + " was not imported, exported, or provided by MDXProvider as global scope")
> 13 | return <div {...props}/>
| ^
14 | };
15 |
Expected behavior The building of my mdx files.
Code snippets Here my main.js and my webpack.config.js. I get it only work in 5.3.9 with both files. perhaps here is the problem.
My main.js:
module.exports = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.js', '../src/**/*.stories.ts', '../src/**/*.stories.tsx'],
addons: [
'@storybook/preset-create-react-app',
'@storybook/addon-actions',
'@storybook/addon-links',
'@storybook/addon-storysource',
'@storybook/addon-knobs/register',
'@storybook/addon-docs',
],
};
My webpack.config.js:
const path = require('path');
const webpack = require("webpack");
module.exports = async ({ config, mode }) => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
include: [path.join(__dirname, '../src'), path.join(__dirname, '../stories')],
use: [
{
loader: require.resolve('awesome-typescript-loader'),
options: {
configFileName: './.storybook/tsconfig.json'
}
},
{
loader: require.resolve('react-docgen-typescript-loader'),
},
]
});
config.resolve.extensions.push('.ts', '.tsx');
// Return the altered config
return config;
};
System: Environment Info:
System:
OS: macOS Mojave 10.14.6
CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
Binaries:
Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.14.1 - ~node_modules/.bin/npm
Browsers:
Chrome: 80.0.3987.122
Firefox: 73.0.1
Safari: 13.0.5
npmPackages:
@storybook/addon-actions: ^5.3.9 => 5.3.14
@storybook/addon-docs: ^5.3.9 => 5.3.14
@storybook/addon-info: ^5.3.9 => 5.3.14
@storybook/addon-knobs: ^5.3.9 => 5.3.14
@storybook/addon-links: ^5.3.9 => 5.3.14
@storybook/addon-storysource: ^5.3.9 => 5.3.14
@storybook/addons: ^5.3.9 => 5.3.14
@storybook/preset-create-react-app: ^1.5.2 => 1.5.2
@storybook/react: ^5.3.9 => 5.3.14
Additional context Thank you!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 9
- Comments: 28 (7 by maintainers)
@nevolgograd delete the whitespace between
<Story>blocks. hopefully this whitespace sensitivity gets fixed in MDX 2.0Have you tried the docs preset with
configureJSX: true?same error occurs when updating
@storybook/preset-create-react-appto3.0.1update
Still have error in @storybook/preset-create-react-app@3.1.0 Downgrading the
@storybook/preset-create-react-appto 3.0.0 will workMaybe this is related đ¤ ? https://github.com/storybookjs/presets/pull/147
update:2
My problem solved upgrade storybook v6.0.0-beta.37 to v6.0.0-beta.38 relate: https://github.com/storybookjs/storybook/pull/11333 (5ff06d2)
Hi everyone! Seems like there hasnât been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we donât have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!
Hit this same issue when running through the Controls walkthrough https://gist.github.com/shilman/69c1dd41a466bae137cc88bd2c6ef487#:~:text=Storybook Controls w%2F CRA %26 TypeScript,ergonomic way to write stories.
Hi everyone! Seems like there hasnât been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we donât have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!
Not sure if this is helpful, but for me the difference between the error above and a working config was this:
I can see it doesnât resemble your config at all, but maybe it would help someone knowledgable such as @shilman to understand where the error comes from.
Sorry for writing in and old closed thread. Just had this issue, but solved it by replacing:
@storybook/addon-essentialswith:as described in the docs here.
Now when you start the storybook server and open it (usually on http://localhost:6006/), you can now see the full error in the console, not just âUnexpected tokenâ (the full error will not be displayed in your terminal). You can also run
build-storybook --debug-webpackto allow webpack to show more error info. In my case there was an old story that used the old way of writing MDX in a regular .md file. That confused the compiler at ton đ.Other errors was:
There was also some incorrect indentation and to space/line-breaks between some JSX code in another .mdx file that the compiler didnât like either (as stated above).
There was an
import React from "react"statement in the top that caused an error.I had two Stories using a
<Story name="Button">that had the same name.Another error was that I had comments in a jsx block, like this:
When I removed all those. It compiled fine.
Hope this fixed can help someone else too.
This is a long shot, but Iâm hoping someone whoâs more familiar with MDXâs intricacies might be able to help me pinpoint my error. Iâve gone line by line and manually checked by deleting code and checking for output and have only been able to successfully get my MDX story to display when I remove everything but the final
return. I canât share my private repo, but as noted hoping someone might be able to pinpoint whats going onâŚI tried adding
configureJsx: trueto storybook addon docs option but that just hangs up my entire Storybook with a blank sidebar and blank page.Hereâs my entire warning:
Along with the code that is causing it from theme.stories.mdx:
Hi everyone! Seems like there hasnât been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we donât have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!