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.

Custom addon not included in bundle after running build-storybook

See original GitHub issue

Bug or support request summary

My custom addon is not being included in the JS bundle after running build-storybook -c .storybook. No errors are thrown when running build-storybook. However, I am seeing the addon on the page and in the Javascript when I run start-storybook.

The result of this is that my custom addon is not displayed in my static storybook build.

Steps to reproduce

I am using typescript in the project and have a custom webpack config for storybook.

module.exports = ({ config }) => {
  config.module.rules.push({
    test: /\.(ts|tsx)$/,
    loader: require.resolve("babel-loader"),
    options: {
      presets: [["react-app", { flow: false, typescript: true }]]
    }
  });
  config.resolve.extensions.push(".ts", ".tsx");
  return config;
};

I’m using a babel.config.js and Babel 7

module.exports = {
  presets: [
    [
      '@babel/env',
      {
        targets: {
          node: '8.9'
        }
      }
    ],
    '@babel/typescript'
  ]
};

My addon.js file is located in the .storybook directory and contains:

import '@storybook/addon-knobs/register';
import './json-addon/register';

I am able to attach the register.js if required. It is working locally for me if I run start-storybook.

This is how I’m registering the addon in register.js

addons.register(ADDON_ID, api => {
  const title = "JSON Content";
  const render = ({ active }) => (
    <JsonPanel
      key={1}
      api={api}
      channel={addons.getChannel()}
      active={active}
    />
  );
  addons.add(PANEL_ID, { type: types.PANEL, title, render });
});

Please specify which version of Storybook and optionally any affected addons that you’re running

Affected platforms

Running on macOS Mojave

Where to start

I followed the docs on these pages for my configuration: https://storybook.js.org/docs/configurations/typescript-config/ https://storybook.js.org/docs/addons/writing-addons/

Acceptance criteria

Successful build-storybook run where the JS bundle contains the addon code so it can be deployed as static files

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
shilmancommented, Jun 5, 2019

From one of our community members on Discord:

I had the same issue […] but managed to resolve it. Found out that it as due to webpack treeshaking my code away. I just had to add a sideEffect reference pointing to my custom addon and then it worked.

1reaction
StJohn3Dcommented, Nov 22, 2019

I had "sideEffects": false in my package jason because I’m writing a component library. Changing it to

"sideEffects": [
    ".storybook/addons/my-addon/register.js"
  ],

Fixed the issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure Storybook
Storybook is a frontend workshop for building UI components and pages in isolation. Thousands of teams use it for UI development, testing, and...
Read more >
Webpack - Storybook
Storybook displays your components in a custom web application built using Webpack. Webpack is a complex tool, but our default configuration is intended...
Read more >
Frequently Asked Questions - Storybook - JS.ORG
Why aren't the addons working in a composed Storybook? Composition is a new feature that we released with version 6.0, and there are...
Read more >
storybook-addon-turbo-build
This addon mainly improves cold build, which is when you build Storybook without caches under your node_modules/.cache . There could be barely noticable ......
Read more >
Publish Storybook
Storybook will create a static web application capable of being served by any web server. Preview it locally by running the following command:....
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