简体   繁体   English

Storybook 未加载故事:错误“无法加载故事‘*’:”

[英]Storybook not loading stories: error "Unable to load story '*':"

I am a complete novice to React.我是 React 的新手。 I switched to a new laptop using a project that worked on my old laptop.我使用在旧笔记本电脑上运行的项目切换到新笔记本电脑。 For some reason it is not working now.由于某种原因,它现在不起作用。 I am getting the following errors.我收到以下错误。 Error shown on console控制台上显示的错误

Storybook picture故事书图片

I downloaded the lastest versions node and npm so I think that might be a cause of the issue.我下载了最新版本的节点和 npm,所以我认为这可能是问题的原因。

I do not have babel in my project so many of the solutions I have found on here do not work for me.我的项目中没有 babel,所以我在这里找到的许多解决方案都不适合我。

I tired to clear the cache in node modules and that did not work我厌倦了清除节点模块中的缓存,但没有用

Really apprectiate if someone could point me in the right direction!!如果有人能指出我正确的方向,我真的很感激!!

As you suggest, the latest version of node and/or npm could be the issue.正如您所建议的,最新版本的节点和/或 npm 可能是问题所在。 It may be good to look in your babelrc file.查看您的 babelrc 文件可能会很好。 This could be something like babel.config.js or.babelrc depending on your project.根据您的项目,这可能类似于 babel.config.js 或 .babelrc。 Babel config files are notorious for causing some issues with newer versions of Storybook. Babel 配置文件因导致较新版本的 Storybook 出现一些问题而臭名昭著。

The few times I have hit this error it is due to something in the babelrc, usually a plugin.有几次我遇到这个错误是由于 babelrc 中的某些东西,通常是一个插件。 A common culprit is the common-js transform module plugin.一个常见的罪魁祸首是common-js transform module插件。

Look for either common-js under preset-env like below:preset-env下寻找common-js ,如下所示:

      {
        modules: 'commonjs', <-- set this to false
        targets: {
          node: 'current'
        },
        loose: true

Or the standalone module babel-plugin-transform-modules-commonjs或者独立模块babel-plugin-transform-modules-commonjs

https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs

And remove that.并删除它。 You may have to make sure that you main application is still able to be bundled correctly- but this can start you down the path of debugging exactly where the issue is.您可能必须确保您的主应用程序仍然能够正确捆绑 - 但这可以让您开始调试问题所在的路径。 I would personally remove all plugins one by one and see if you have any luck.我会亲自将所有插件一一删除,看看您是否有运气。

If you have your own babelrc for the Storybook itself- perhaps look here.如果您有自己的故事书本身的babelrc - 也许看这里。 It may not be being utilized like you think.它可能没有像您想象的那样被利用。

https://github.com/babel/babel-loader/issues/780 https://github.com/babel/babel-loader/issues/780

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

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