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.

Installing Emotion 11 breaks storybook-builder-vite

See original GitHub issue

Trying to use storybook-builder-vite as the builder when you have Emotion 11 installed breaks docs pages with an Uncaught TypeError: Cannot read properties of undefined (reading 'content') in one of the MDX/docs pages’ <Styled(div)> elements because the Emotion theme is empty.

Reproduction

  1. npx sb init --type react - Initialize storybook
  2. npm install react react-dom storybook-builder-vite - Add React and storybook-builder-vite
  3. Add core: { builder: 'storybook-builder-vite' } to configure storybook-builder-vite
  4. npm run storybook - The Introduction page in Storybook works now
  5. npm install @emotion/react @emotion/styled - Install Emotion 11
  6. npm run storybook - The Introduction page is now broken

More information

Lots of projects have upgraded to Emotion v11. This includes libraries like MUI, where it’s not possible to just downgrade back to Emotion v10.

Storybook is currently running Emotion v10. However running the normal Webpack4 builder docs pages still work, even when running with features.emotionAlias: false, to ensure that the project’s own Emotion v11 theme provider works.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
joshwoodingcommented, Jan 27, 2022

@dantman You should be able to use this solution: https://github.com/storybookjs/storybook/issues/16716#issuecomment-1020613602

I’ve tested it locally and it works, all you need to to is use the viteFinal setup instead.

  async viteFinal(config) {
    config.resolve.alias = {
        ...config.resolve.alias,
      '@emotion/react': path.resolve(path.join(__dirname, '../node_modules/@emotion/react')),
      '@emotion/styled': path.resolve(path.join(__dirname,'../node_modules/@emotion/styled')),
      '@emotion/core':path.resolve(path.join(__dirname, '../node_modules/@emotion/react')),
      'emotion-theming': path.resolve(path.join(__dirname, '../node_modules/@emotion/react')),
    }
    return config;
  },
1reaction
IanVScommented, Feb 1, 2022

It looks like storybook is also working on improving their compatibility with emotion 11: https://github.com/storybookjs/storybook/pull/17000

Read more comments on GitHub >

github_iconTop Results From Across the Web

Installing Emotion 11 breaks storybook-builder-vite · Issue #219
Storybook is currently running Emotion v10. However running the normal Webpack4 builder docs pages still work, even when running with features.
Read more >
Vite - Storybook
Storybook Vite builder bundles your components and stories with Vite, a fast ESM bundler. For applications built with Vite: it allows reusing the...
Read more >
storybook-builder-vite - npm
An experimental plugin to run and build Storybooks with Vite. Latest version: 0.1.23, last published: 8 months ago. Start using storybook-builder-vite in ...
Read more >
Storybook vite failed to build with ChakraUI / React 18
I used latest version of chakra, react 18, emotion 11 and storybook 6.5 with vite builder. I tried with webpack 4 and 5...
Read more >
MIGRATION.md - Storybook - Fossies
Prior to SB6.5, addon-actions provided an option called addDecorators . In SB6.5, decorators are applied always. This is technically a breaking change, so...
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