52

I'm trying to load up the demo storybook stories (withText, withIcon), using this react guide, but I cannot get any of the example stories to run.

For the avoidance of doubt, here's the code file (Histogram.stories.js):

import React from 'react';
import { Button } from '@storybook/react/demo';

export default { title: 'Button' };

export const withText = () => <Button>Hello Button</Button>;

export const withEmoji = () => (
  <Button>
    <span role="img" aria-label="so cool">
         
    </span>
  </Button>
);

And my main.js

module.exports = {
    stories: ['../src/**/*.stories.jsx?'],
};

When I run npm run storybook I get this page:

storybookpage with no stories

This is the output in the devconsole:

vendors~main.9bf87aec509ee033c0f8.bundle.js:135070 Download the React DevTools for a better development experience: https://fb .me/react-devtools
DevTools failed to parse SourceMap: chrome-extension://gighmmpiobklfepjocnamgkkbiglidom/include.preload.js.map
DevTools failed to parse SourceMap: chrome-extension://gighmmpiobklfepjocnamgkkbiglidom/include.postload.js.map
DevTools failed to parse SourceMap: http://localhost:60923/unfetch.mjs.map

Which doesn't show what went wrong.

Likewise I cant see whats wrong with the set up on the command line

> start-storybook

info @storybook/react v5.3.18
info 
info => Loading presets
info => Loading presets
info => Adding stories defined in ".storybook\main.js".
info => Using default Webpack setup.
info => Using base config because react-scripts is not installed.
webpack built 618e1f89c3579e851a85 in 52146ms
╭────────────────────────────────────────────────────╮
│                                                    │
│   Storybook 5.3.18 started                         │
│   1.37 min for manager and 1.37 min for preview    │
│                                                    │
│    Local:            http://localhost:60923/       │
│    On your network:  http://192.168.0.15:60923/    │
│                                                    │
╰────────────────────────────────────────────────────╯

The only CLI option I can find, that seems relevant, is --debug-webpack but this does not produce further output in my case.

What can I do to further troubleshoot this problem?

AncientSwordRage
  • 7,086
  • 19
  • 90
  • 173
  • Hey did you use create-react-app for this project or did you do it yourself? – Y4glory Apr 06 '20 at 12:01
  • @Y4glory I did this mysef bu I copied some configuration from a colleague – AncientSwordRage Apr 07 '20 at 00:43
  • can you give me a sample of your project structure? – Y4glory Apr 07 '20 at 05:33
  • @Y4glory it's a pretty flat structure, but I can't put it anywhere publicly. It's just `src/components/Histogram.js` and `src/components/Histogram.stories.js`, and at the base level I have `.babelrc`, everything else is like `.gitignore` or `.eslintrc` etc. – AncientSwordRage Apr 07 '20 at 11:38
  • Can you check your `main.js` in `.storybook` folder to make sure you have this line? `stories: ['../src/**/*.stories.js'],` – Y4glory Apr 07 '20 at 11:53
  • I'm down to set up this guide, but your "error" says you have no stories selected. Is there something you are missing with "selecting stories"? Or is this just a generic error because your config is not legit? Y4glory's last question has gone unanswered for 15 hours. Do you still need help? – Brian Patterson Apr 08 '20 at 03:25
  • @Y4glory apologies, I thought I had already added the `main.js` to the question. I've added it now. – AncientSwordRage Apr 08 '20 at 09:03
  • @BrianPatterson Yes I still need help. – AncientSwordRage Apr 08 '20 at 09:03
  • Hey the issue is in your main.js @Pureferret it says jsx at the end whereas your file is a js file :) – Y4glory Apr 08 '20 at 09:06
  • @Y4glory I tried both js and jsx, but I thought the [`?` is part of the regex](https://www.regular-expressions.info/optional.html) that means it may or may not have an x. I did have the path wrong at one point, and it's a different error from this time. – AncientSwordRage Apr 08 '20 at 09:24
  • Nope it seems to work now. It's weird because the example gives `'../src/**/*.stories.[tj]s'` which made me think it would read all regex. – AncientSwordRage Apr 08 '20 at 09:25
  • hmm yea I don't think it's compatible for `?` maybe they will make it compatible in the future, or maybe you have to try js(x)? – Y4glory Apr 08 '20 at 09:27
  • I think question and accepted answer do not match. I suggest either one to be changed. – DarkTrick Nov 07 '22 at 02:23
  • @DarkTrick there hasn't been a better answer as far as I can see. Feel free to post one. – AncientSwordRage Nov 07 '22 at 03:53

9 Answers9

31

The main.js in your ./storybook folder contains the line stories: ['../src/**/*.stories.jsx?'], since your story is named Histogram.stories.js it should be like below.

module.exports = {
  stories: ['../src/**/*.stories.js']
};

I tried replicating this in my code by using your main.js and the exact same thing happened to me as well. Also adding the ? like this stories: ['../src/**/*.stories.js?'] gives the same error

Edit- you can check for both .js and .jsx by modifying the line like this stories: ['../src/**/*.stories.js(x)?']

Edit (24/7/2021) - As of today while installing storybook with npx sb init and choosing react as the template it automatically adds the below snippet in the main.js file

module.exports = {
  "stories": [
    "../stories/**/*.stories.mdx",
    "../stories/**/*.stories.@(js|jsx|ts|tsx)"
  ],
  "addons": [
    "@storybook/addon-links",
    "@storybook/addon-essentials"
  ]
}

which solves for this issue

Y4glory
  • 1,111
  • 6
  • 17
  • Hi I donot have a main.js file in my storybook folder. So what should I do? – Ritika Gupta Jul 02 '21 at 05:09
  • @RitikaGupta how did you setup your project? I'm assuming you used create-react-app and then added storybook using npx sb init – Y4glory Jul 24 '21 at 13:37
  • @AncientSwordRage How is this the accepted answer? The question says *How to troubleshoot storybook not loading stories*. This answer does not help with general troubleshooting, but rather solves one specific use case. – DarkTrick Nov 07 '22 at 02:23
19

Removing the node_modules/.cache/storybook folder and restarting Storybook is what worked for me.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Aakash
  • 21,375
  • 7
  • 100
  • 81
7

Check the console of the chrome window running localhost. You should see errors there. I had a component not showing up but the project ran smoothly and took me a bit to figure out what error and where it was coming

Shane Walker
  • 301
  • 3
  • 7
3

Resave save the story file. It makes the component reappear in side panel, and then you can see the errors.

start-storybook seems to fail silently. But you can troubleshoot errors by resaving files one by one.

Jkarttunen
  • 6,764
  • 4
  • 27
  • 29
  • Oh thanks, this saved me from debugging problem for hours. Interesting that code failed but storybook only displayed warning. Full build succeeded without problems, I would expect storybook to fail build if there are stories which are failing :o – Jurosh Jul 05 '21 at 09:32
1

I had this same problem of "stories not showing up in storybook UI" that brought me here. Turns out, I had pasted in some test code that set a regEx on "excludeStories" to filter out any story function with the word "Data" in it. Of course, my disappearing story was named "StoryWithData", so it was excluded.

This took me way too long to figure this out, so posting here in case helps someone else.

export default {
  component: Footer,
  title: "App/Footer",
  excludeStories: /.*Data$/,  // -> this will filter out functions named like  "*Data"
}
mrjbj
  • 329
  • 1
  • 10
  • 2
    The recommended setup is to use `includeStories: /^[A-Z]/` instead of excludeStories. This will treat any export that starts with a capital letter as a story, which is great because it enforces the PascalCase naming convention for stories. – Gert Hengeveld Jan 06 '21 at 08:41
1

In my case, I had to clear the browser's local storage. There was an older storybook application running on localhost:6006

Atilla Baspinar
  • 925
  • 1
  • 12
  • 17
1

There is another scenario when some stories do not load (it took me a while to figure this one out).

When your story path is a substring of another story path, both the stories won't load (silent fail).

For example:

Path 1: foo/bar

Path 2: foo/bar/baz

This is because Storybook seems to consider rendering stories only for leaf nodes of the tree. In the above case, the foo/bar is NOT a leaf node, which makes the Storybook confused, so it gives up on everything (the whole subtree).

I also suspected that my story doesn't render because of the depth being to deep, but it seems any depth of stories is allowed:

foo1/foo2/foo3/foo4/foo5/foo6... -> fully valid story path.

Danko Kozar
  • 221
  • 2
  • 8
-1

you should use as

 module.exports = {
  stories: ['../src/**/*.stories.(ts|js|mdx)']
};

basically handle all types of storries.

-1

You should run storybook server and then after run the react native app then if you refresh the webpage for react native server the stories should load.

devbiswasnegi
  • 280
  • 2
  • 5