question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
birdofpreyrucommented, Nov 2, 2021

babel-preset-svgr covers that 😉

1reaction
gregbergecommented, Sep 26, 2021

Yeah, SVGR is not available as a babel-plugin yet, but I will work on it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found