简体   繁体   English

如何解决故事书未加载故事的问题?

[英]How to troubleshoot storybook not loading stories?

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.我正在尝试使用此反应指南加载演示故事书故事( withTextwithIcon ),但我无法运行任何示例故事。

For the avoidance of doubt, here's the code file (Histogram.stories.js):为免生疑问,这里是代码文件(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还有我的main.js

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

When I run npm run storybook I get this page:当我运行npm run storybook时,我得到这个页面:

没有故事的故事书页

This is the output in the devconsole:这是 devconsole 中的 output:

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.我能找到的唯一似乎相关的 CLI 选项是--debug-webpack ,但在我的情况下,这不会产生进一步的 output 。

What can I do to further troubleshoot this problem?我可以做些什么来进一步解决这个问题?

Removing the node_modules/.cache/storybook folder and restarting Storybook is what worked for me.删除node_modules/.cache/storybook文件夹并重新启动 Storybook 对我有用。

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. main.js文件夹中的./storybook包含行stories: ['../src/**/*.stories.jsx?'],因为你的故事被命名为Histogram.stories.js ,它应该如下所示。

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.我尝试使用您的main.js在我的代码中复制它,并且完全相同的事情也发生在我身上。 Also adding the ?还添加? like this stories: ['../src/**/*.stories.js?'] gives the same error像这样stories: ['../src/**/*.stories.js?']给出了同样的错误

Edit- you can check for both .js and .jsx by modifying the line like this stories: ['../src/**/*.stories.js(x)?']编辑 - 您可以通过修改以下行来检查.js.jsx 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编辑(2021 年 7 月 24 日)-截至今天,在使用 npx npx sb init安装 storybook 并选择 react 作为模板时,它会自动在 main.js 文件中添加以下代码段

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

which solves for this issue解决了这个问题

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. start-storybook似乎默默地失败了。 But you can troubleshoot errors by resaving files one by one.但是您可以通过一一重新保存文件来解决错误。

I had this same problem of "stories not showing up in storybook UI" that brought me here.我遇到了同样的问题,即“故事书 UI 中没有显示故事”,这让我来到了这里。 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.原来,我粘贴了一些测试代码,在“excludeStories”上设置了一个正则表达式,以过滤掉任何带有“数据”一词的故事 function。 Of course, my disappearing story was named "StoryWithData", so it was excluded.当然,我消失的故事被命名为“StoryWithData”,所以被排除在外。

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"
}

you should use as你应该用作

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

basically handle all types of storries.基本上处理所有类型的故事。

First of all look at any warnings/errors printed in start-storybook script.首先查看start-storybook脚本中打印的任何警告/错误。 Script can quietly allow some deprecations or misconfigurations.脚本可以悄悄地允许一些弃用或错误配置。

Then I would compare your ./storybook/main.js file with one from docs of your chosen version.然后,我会将您的./storybook/main.js文件与您选择的版本的文档中的一个文件进行比较。

For after version upgrade problems I strongly suggest following Storybook migration guides.对于版本升级后的问题,我强烈建议遵循 Storybook 迁移指南。 They usually provide change log and code mod tools.他们通常提供更改日志和代码修改工具。

https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#from-version-63x-to-640 https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#from-version-63x-to-640

Check the console of the chrome window running localhost.检查运行 localhost 的 chrome window 的控制台。 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我有一个组件没有出现,但项目运行顺利,我花了一点时间来弄清楚什么错误以及它来自哪里

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.您应该运行故事书服务器,然后在运行反应本机应用程序之后,如果您刷新网页以反应本机服务器,则应该加载故事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM