question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Storybook doesn't work with gatsby

See original GitHub issue

Describe the bug When I want to run Storybook with Gatsby following by these instructions: https://www.gatsbyjs.com/docs/how-to/testing/visual-testing-with-storybook/#setting-up-your-environment, the Storybook is running but I see only a loader and I get this error in dev tools: image error: image

When I comment this line

config.module.rules[0].exclude = [/node_modules\/(?!(gatsby)\/)/]

Storybook runs, but I can’t use Gatsby components. The problem exist even with default stories that came from Storybook init.

To Reproduce This is the link to repo where problem exists: https://github.com/moose96/gatsby-storybook-test.

System Environment Info:

System: OS: Windows 10 10.0.19041 CPU: (8) ia32 Intel® Core™ i5-1035G1 CPU @ 1.00GHz Binaries: Node: 14.17.0 - C:\Program Files (x86)\nodejs\node.EXE Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD npm: 6.14.13 - C:\Program Files (x86)\nodejs\npm.CMD Browsers: Edge: Spartan (44.19041.1023.0), Chromium (91.0.864.64) npmPackages: @storybook/addon-actions: ^6.3.4 => 6.3.4 @storybook/addon-essentials: ^6.3.4 => 6.3.4 @storybook/addon-links: ^6.3.4 => 6.3.4 @storybook/builder-webpack5: ^6.3.4 => 6.3.4 @storybook/manager-webpack5: ^6.3.4 => 6.3.4 @storybook/react: ^6.3.4 => 6.3.4.

Additional Context

  • Gatsby version: 3.9.0
  • React version: 17.0.1
  • Storybook version: 6.3.4

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
usrrnamecommented, Sep 6, 2021

I got Storybook 6.3.7 to work with Gatsby 3 last weekend. What I did was to follow the Gatsby install instructions and introduced the following config.resolve.alias block into my main.ts :

module.exports = {
  stories: ['../src/**/*.stories.@(jsx|tsx|mdx)'],
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-docs',
    '@storybook/addon-essentials',
  ],
  typescript: {
    check: true,
  },
  core: {
    builder: 'webpack5',
  },
  webpackFinal: async (config: any) => {
    // Transpile Gatsby module because Gatsby includes un-transpiled ES6 code.
    config.module.rules[0].exclude = [/node_modules\/(?!(gatsby)\/)/];
    // Use babel-plugin-remove-graphql-queries to remove static queries from components when rendering in storybook
    config.module.rules[0].use[0].options.plugins.push(
      require.resolve('babel-plugin-remove-graphql-queries')
    );
    config.resolve.alias = {
      ...config.resolve.alias,
      path: require.resolve('path-browserify'),
      crypto: require.resolve('crypto-browserify'),
      stream: require.resolve('stream-browserify'),
    };
    return config;
  },
};

0reactions
shilmancommented, Sep 3, 2021

closing as dupe to #15820

Read more comments on GitHub >

github_iconTop Results From Across the Web

StoryBook does not work with GatsbyJS · Issue #17176 - GitHub
Describe the bug StoryBook doesnt work with GatsbyJS To Reproduce Create a new project using GatsbyJS npm install -g gatsby-cli gatsby new ...
Read more >
Visual Testing with Storybook | Gatsby
Knowing your components look as intended in every permutation is an excellent way to test them visually and provides “living documentation” for them....
Read more >
Gatsby Addon | Storybook: Frontend workshop for UI ...
Storybook addon used to load stories built with Gatsby. Note: This addon requires Storybook to be configured for Webpack 5. See the official...
Read more >
CSS Modules import behaves differently in Gatsby vs Storybook
Any recommendations on how to configure Storybook to handle the CSS modules import in the same way as Gatsby? Ideally I would like...
Read more >
Adding Storybook to a Gatsby site - Sam Bunting
Because Gatsby likes to run... Using Gatsby - You need to tell Storybook to run a bit like Gatsby as well. In fact...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found