Skip to content
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

Manual Config of Docs not working. #9632

Closed
lpoulter opened this issue Jan 25, 2020 · 8 comments
Closed

Manual Config of Docs not working. #9632

lpoulter opened this issue Jan 25, 2020 · 8 comments

Comments

@lpoulter
Copy link

lpoulter commented Jan 25, 2020

Describe the bug
After following the instructions here on a fresh install of storybook. The app compiles but the interface hangs with no errors.

To Reproduce
npx -p @storybook/cli sb init
yarn add -D @storybook/addon-docs
yarn add -D react react-is babel-loader
Make the changes here
Expected behavior
The app to load with the docs addon working.

Screenshots
Screen Shot 2020-01-25 at 09 19 47

Code snippets
Main.js

module.exports = {
  stories: ["../src/**/*.stories.js"],
  addons: [
    "@storybook/preset-create-react-app",
    "@storybook/addon-actions",
    "@storybook/addon-links",
    "@storybook/addon-docs/register"
  ]
};

const createCompiler = require("@storybook/addon-docs/mdx-compiler-plugin");

module.exports = {
  webpackFinal: async config => {
    config.module.rules.push({
      test: /\.(stories|story)\.mdx$/,
      use: [
        {
          loader: "babel-loader",
          // may or may not need this line depending on your app's setup
          options: {
            plugins: ["@babel/plugin-transform-react-jsx"]
          }
        },
        {
          loader: "@mdx-js/loader",
          options: {
            compilers: [createCompiler({})]
          }
        }
      ]
    });
    config.module.rules.push({
      test: /\.(stories|story)\.[tj]sx?$/,
      loader: require.resolve("@storybook/source-loader"),
      exclude: [/node_modules/],
      enforce: "pre"
    });
    return config;
  }
};

Preview.js

import { addParameters } from "@storybook/react";
import { DocsPage, DocsContainer } from "@storybook/addon-docs/blocks";

addParameters({
  docs: {
    container: DocsContainer,
    page: DocsPage
  }
});
@raikusy
Copy link

raikusy commented Jan 26, 2020

I am facing the same issue. Any idea how to fix it? It's happening after upgrading to v5.3.9

@lpoulter
Copy link
Author

lpoulter commented Jan 26, 2020

I tested this with a clean install of 5.3 and the bug is still there. I suspect the config in the docs are wrong or missing something.

@shilman
Copy link
Member

shilman commented Jan 26, 2020

Yeah I think the docs need updating. Can you share a repro repo if you have one handy?

@lpoulter
Copy link
Author

lpoulter commented Jan 26, 2020

@shilman
Copy link
Member

shilman commented Jan 26, 2020

Thanks I’ll take a look! 🙏

@shilman
Copy link
Member

shilman commented Jan 26, 2020

The docs are actually correct-ish, just unclear. I've updated them in #9638

The bug is here:

https://github.com/lpoulter/doc-mdx-bug/blob/master/.storybook/main.js#L9-L13

The code is overwriting module.exports, so module.exports.stories is undefined. @ndelangen is it easy to detect this case in Storybook and show a "no stories loaded" state to help users debug cases like this? Right now, the UI just hangs in a not-very-helpful way.

@lpoulter would you mind reviewing the PR and let me know if it makes more sense? Thanks for you help & patience!

@lpoulter
Copy link
Author

That was pretty clear to see but hadn't occurred to me, thanks very much.

@shilman
Copy link
Member

shilman commented Jan 26, 2020

No worries. Everything’s clear in hindsight. Closing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants