Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid value for prop css when using @emotion/react with Vite #17196

Closed
akbarkz opened this issue Jan 11, 2022 · 1 comment
Closed

Invalid value for prop css when using @emotion/react with Vite #17196

akbarkz opened this issue Jan 11, 2022 · 1 comment

Comments

@akbarkz
Copy link

akbarkz commented Jan 11, 2022

Describe the bug
I couldn't find any information on how to make @emotion/react work in Storybook when using Vite as a bundler in a React application.
I'm getting errors like Invalid value for prop 'css' in <div> tag in almost every story. Even though, @emotion/react is working fine for the webapp itself.

Here's my vite.config.js configuration:

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  esbuild: {
    jsxFactory: 'jsx',
    jsxInject: `import { jsx } from '@emotion/react'`,
  },
  plugins: [
    react({
      jsxImportSource: '@emotion/react',
      babel: {
        plugins: ['@emotion/babel-plugin'],
      },
    }),
  ],
});

And here's my main.js for Storybook:

const svgrPlugin = require('vite-plugin-svgr');

module.exports = {
  core: {
    builder: 'storybook-builder-vite',
  },
  stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
  addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
  viteFinal: (config, { configType }) => {
    config.define = {
      'window.process': {
        env: {
          NODE_ENV: configType.toLowerCase(),
        },
      },
    };
    return {
      ...config,
      plugins: [
        ...config.plugins,
        svgrPlugin({
          svgrOptions: {
            icon: true,
          },
        }),
      ],
    };
  },
};

To Reproduce
Sorry, I failed with trying to create a reproducible repository.
Versions of packages that I use:
react - 16.14.0
@emotion/react - 11.7.1
@emotion/babel-plugin - 11.7.1
storybook-builder-vite - 0.1.11
vite - 2.7.3
vite-plugin-svgr - 0.6.0
@vitejs/plugin-react - 1.1.3

System
Environment Info:

System:
OS: Linux 5.6 Ubuntu 20.04.3 LTS (Focal Fossa)
CPU: (8) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
Binaries:
Node: 14.15.4 - ~/.nvm/versions/node/v14.15.4/bin/node
Yarn: 1.19.1 - /usr/bin/yarn
npm: 6.14.10 - ~/.nvm/versions/node/v14.15.4/bin/npm
Browsers:
Chrome: 95.0.4638.69
Firefox: 94.0
npmPackages:
@storybook/addon-actions: ~6.3.8 => 6.3.12
@storybook/addon-essentials: ~6.3.8 => 6.3.12
@storybook/addon-links: ~6.3.8 => 6.3.12
@storybook/node-logger: ~6.3.8 => 6.3.12
@storybook/react: ~6.3.8 => 6.3.12

Additional context
There are ways how to make @emotion/react work when one is using Webpack as a bundler, but unfortunately I couldn't find anything related to Vite.

@shilman
Copy link
Member

shilman commented Jan 12, 2022

Please file Vite-related issues in https://github.com/eirslett/storybook-builder-vite/

Closing this for now--please let me know if you think this ISN'T Vite-related and I'll reopen. Thank you! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants