Cannot use babel-plugin-transform-svg-component, throws error
See original GitHub issue🐛 Bug Report
When using @svgr/babel-plugin-transform-svg-component
, or in my case the @svgr/babel-preset
an error is thrown
TypeError: <path to file containing svg>: Cannot read property 'componentName' of undefined
I did some tracing and found this. It seems that the plugin makes a reference to opts.state.componentName
without checking for it first, and doesn’t provide a default value.
I’d like to be able to use svgr with just babel. Am I doing something wrong, or is there an actual bug here?
To Reproduce
Steps to reproduce the behavior:
Create a project with the following babel config, and import/require an svg file:
.babelrc.js
module.exports = {
presets: [
'@svgr/babel-preset'
]
}
Expected behavior
SVGR does it’s magic and inlines the SVG.
Actual behavior
It throws an exception because an option has not been provided, that to my knowledge is impossible to pass.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
@svgr/babel-plugin-transform-svg-component - npm
@svgr/babel-plugin-transform-svg-component. TypeScript icon, indicating that this package has built-in type declarations.
Read more >Jest cannot load svg file - Stack Overflow
svg files from an icon library in node_modules 1. Using jest-transform-stub in the "transform" section of jest.config.js did not work for me, ...
Read more >babel-plugin-inline-react-svg | Yarn - Package Manager
A babel plugin that optimizes and inlines SVGs for your react components. ... Transforms imports to SVG files into React Components, and optimizes...
Read more >Troubleshooting Common Errors - Gatsby
Errors in styling. Inconsistent CSS styles between develop and build using styled-components or emotion. Errors with GraphQL. Unknown field 'A' on type 'B'....
Read more >Webpack - SVGR
Transforms SVG into React Components. ... provides an official webpack.js loader to import SVG as React components. ... Use your own Babel configuration....
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 FreeTop 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
Top GitHub Comments
babel-preset-svgr covers that 😉
Yeah, SVGR is not available as a babel-plugin yet, but I will work on it.