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

Preview doesn't load svg components correctly #5898

Closed
ying-rao opened this issue Mar 6, 2019 · 1 comment
Closed

Preview doesn't load svg components correctly #5898

ying-rao opened this issue Mar 6, 2019 · 1 comment

Comments

@ying-rao
Copy link

ying-rao commented Mar 6, 2019

Describe the bug
Preview doesn't render the svg files imported as a React component correctly even with the custom webpack config. It always looks for the svg file under static/media.

To Reproduce
Steps to reproduce the behavior:

  1. import the svg as a React component
import Logo from "../icons/logo.svg";

export function container() {
  return <div>
      <Logo />
  </div>;
}
  1. Run "start-storybook -p 6006 -c .storybook"

  2. Storybook ui is loaded with the preview of components. Error is shown on the preview of the container component.
    Failed to execute 'createElement' on 'Document': The tag name provided ('static/media/logo.717fead6.svg') is not a valid name.
    Error: Failed to execute 'createElement' on 'Document': The tag name provided ('static/media/logo.717fead6.svg') is not a valid name.

Expected behavior
The component is rendered correctly with the svg file.

Code snippets
webpack.config.js

const path = require('path');

module.exports = {
    module: {
        rules: [
            {
                test: /\.scss$/,
                loaders: ['style-loader', 'css-loader', 'sass-loader'],
                include: path.resolve(__dirname, '../'),
            },
            {
                test: /\.(js|jsx|mjs)$/,
                loader: require.resolve('babel-loader'),
                options: {
                    cacheDirectory: true,
                },
            },
            {
                test: /\*.svg$/,
                use: [
                    {
                        loader: require.resolve("babel-loader")
                    },
                    {
                        loader: require.resolve("react-svg-loader"),
                        options: {
                            jsx: true
                        }
                    }
                ]
            }
        ],
    },
};

System:

  • OS: MacOS
  • Browser: Chrome
  • Framework: React
  • Version: 5.0.0
@shilman
Copy link
Member

shilman commented Mar 6, 2019

Yeah, hope to fix that today! Closing this as a duplicate to #5708

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