【发布时间】:2019-06-15 00:03:30
【问题描述】:
我正在尝试将 Storybook 添加到现有的 React 应用程序,但导入的 svg 文件出现错误。 svg 的导入和使用如下:
import Border from './images/border.inline.svg'
...
<Border className="card__border" />
这在应用程序运行和构建时有效,但我在 Storybook 中遇到错误。怎么会?
Failed to execute 'createElement' on 'Document': The tag name provided ('static/media/border.inline.258eb86a.svg') is not a valid name.
Error: Failed to execute 'createElement' on 'Document': The tag name provided ('static/media/border.inline.258eb86a.svg') is not a valid name.
默认的 webpack.config.js 有:
...
{
test: /\.inline.svg$/,
loader: 'svg-react-loader'
},
...
另外,现有代码使用 webpack 3,而我使用的是 Storybook V4。
【问题讨论】: