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.

How to use babel-emotion-plugin with Storybook + Typescript?

See original GitHub issue

I am currently using Storybook (v.4.0.12) with TypeScript and have successfully followed the instructions to set up my TypeScript webpack.config.js. This works fine.

However, I cannot seem to find any way of successfully adding a babel plugin to the config. My latest attempt is below, which does not work.

module.exports = (baseConfig, env, config) => {
  config.module.rules.push({
    test: /\.(ts|tsx)$/,
    use: [
      {
        loader: require.resolve('awesome-typescript-loader'),
        options: {
          babelOptions: {
            babelrc: false,
            presets: [],
            plugins: ['emotion'],
          },
        },
      },
    ],
  });
  config.resolve.extensions.push('.ts', '.tsx');

  return config;
};

If I boot Storybook with this config, I continue to see the message Component selectors can only be used in conjunction with babel-plugin-emotion., which means that the Emotion babel plugin is not being picked up by Storybook.

I am not using CRA, just plain ol’ React and Typescript.

Any suggestions?

Thanks.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:13
  • Comments:17 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
stale[bot]commented, Apr 20, 2019

Hey there, it’s me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

5reactions
Elfo404commented, May 27, 2020

@MarkLyck crossposting it here from SO so other people might find it as well.

I don’t know if it applies to everyone, but in my case I got it working with storybook 5.3.x by using in .storybook/main.js this:

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

This doesn’t use TypeScript tho, so might or might not be relevant in this situation, or might just be used while a solution using TypeScript is found.

Hope it helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use babel-emotion-plugin with Storybook + Typescript?
If I boot Storybook with this config, I continue to see the message "Component selectors can only be used in conjunction with babel-plugin- ......
Read more >
How to use babel-emotion-plugin with Storybook + Typescript?
I don't know if might solve your issue, but i got mine by just using this configuration in .storybook/main.js : module.exports = {...
Read more >
Setting up Storybook with React, TypeScript and Emotion
Learn how to setup Storybook with React, TypeScript, and Emotion.
Read more >
duncanleung/gatsby-typescript-emotion-storybook
duncanleung/gatsby-typescript-emotion-storybook. This Sandbox is in sync with master on GitHub. You have to fork to make changes. Fork. Files .storybook.
Read more >
Babel - Storybook
Check out our source to learn more about these plugins. Custom config file. If your project has a .babelrc file, we'll use that...
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