SVG imports are undefined
See original GitHub issueDescribe the bug When I import SVGs into storybook, the imports are undefined.
To Reproduce
import React from 'react'
import { storiesOf } from '@storybook/react'
import { ReactComponent as Example } from './example.svg'
console.log(Example) // undefined
Expected behavior The SVG should be imported successfully.
Code snippets If applicable, add code samples to help explain your problem.
System:
- OS: OSX
- Device: Macbook Pro 2018
- Browser: N/A
- Framework: N/A
- Addons: Not relevant
- Version:
"@storybook/react": "^4.1.11"
Additional context Judging by this issue, this should be supported out of the box without a custom Webpack or Babel config.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Getting undefined when importing svg as ReactComponent in ...
To import an SVG: import MySvg from "MySvg.svg" which will save the path as a string inside MySvg . To render it, use...
Read more >Importing SVG into Meteor/React - help
Hey guys, since it is “trendy” to import SVGs directly into your code, I'm wondering if anyone from you has some instructions for...
Read more >Options - SVGR
"classic": adds import * as React from 'react' on the top of file ... SVG nodes with uppercase and use a specific template...
Read more >Why do I keep getting this error: "Element type is invalid" when ...
import { ReactComponent as MyIcon } from "../../assets/icons/12x12/arrow-down-12.svg" and when I render MyIcon , I keep getting this error: ...
Read more >SVG Error? - Pixelmator Community
Andrew Hart. on undefined undefined, Sun. Hi. I'm trying to edit an SVG file, but when I import it to Pixelmator Pro one...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For those interested, I was able to get
.svg
imports working using the following custom webpack configfor reference: https://storybook.js.org/docs/configurations/custom-webpack-config/
hey @pedrombafonso, thank you for the solution.
but let’s try to make it more adaptable: