Skip to content

It's not possible to export decorator that contains React or HTML tags Storybook 6.0 #11723

@bdobry

Description

@bdobry

Describe the bug
When trying to export a decorator that contains React or HTML tags, Storybook returns an error.

To Reproduce
Steps to reproduce the behavior:

  1. Create a preview.js with for example:
export const decorators = [story => <div>story()</div>];
  1. Run Storybook
  2. See error:
    You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.
    image

Expected behavior
Storybook exports decorator

Additional context
I tried adding such rule to webpack:

{
    test: /\.js?$/,
    use: "babel-loader",
    exclude: /node_modules/
}

but then the error is:
Support for the experimental syntax 'jsx' isn't currently enabled
image

My main goal here was to globally wrap my components with <MemoryRouter /> from react-router-dom and Redux <Provider /> instead of doing that every time. If there's any other way of doing that I'm open for suggestions.

Code snippets

// main.js
const appConfig = require("../webpack.config");

module.exports = {
  addons: [
    "@storybook/addon-viewport",
    {
      name: "@storybook/addon-docs",
      options: {
        configureJSX: true,
        babelOptions: {},
        sourceLoaderOptions: null
      }
    }
  ],
  stories: ["../src/**/*.stories.tsx"],
  typescript: {
    check: false,
    checkOptions: {},
    reactDocgen: "react-docgen-typescript",
    reactDocgenTypescriptOptions: {
      shouldExtractLiteralValuesFromEnum: true,
      shouldRemoveUndefinedFromOptional: true,
      propFilter: prop =>
        prop.parent ? !/node_modules/.test(prop.parent.fileName) : true
    }
  },
  webpackFinal: config => {
    return {
      ...config,
      module: {
        ...config.module,
        rules: appConfig.module.rules
      },
      resolve: {
        ...config.resolve,
        alias: appConfig.resolve.alias
      }
    };
  }
};

System:
System:
OS: macOS 10.15.4
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz

Binaries:
Node: 12.16.3 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.5 - /usr/local/bin/npm

Browsers:
Chrome: 84.0.4147.89
Firefox: 78.0.2
Safari: 13.1

npmPackages:
@storybook/addon-docs: 6.0.x-rc.16 => 6.0.0-rc.16
@storybook/addon-viewport: 6.0.x-rc.16 => 6.0.0-rc.16
@storybook/addons: 6.0.x-rc.16 => 6.0.0-rc.16
@storybook/react: 6.0.x-rc.16 => 6.0.0-rc.16

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions