Can't import SVG components from external packages
See original GitHub issueCan you reproduce the problem with latest npm?
Yes, I can.
Description
Can’t import react components that contain SVG elements like <svg>
, <g>
, etc from external packages.
Expected behavior
Files should be imported correctly.
Actual behavior
I’m getting
Module parse failed: /Users/stepan/projects/velobike/node_modules/@urbica/components/src/Chart/index.jsx Unexpected token (43:6)
You may need an appropriate loader to handle this file type.
|
| return (
| <svg height={this.props.height} width={this.props.width}>
| <g transform={transform}>
| {children}
Environment
npm ls react-scripts
(if you haven’t ejected):
velobike@0.3.0 /Users/stepan/projects/velobike
└── react-scripts@1.0.0
-
node -v
:7.10.0
-
npm -v
:4.6.1
-
Operating system: macOS 10.12.5
Reproducible Demo
To reproduce this issue you can try to import any component from @urbica/components.
Eg.
import { Axis, Area, Chart } from '@urbica/components';
FYI this library uses jsnext:main
param in package.json
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Unable to import SVG with Vite as ReactComponent
In App.tsx import SVG as React Component by adding ?component on the svg's import directive : import Happy from '.
Read more >How to Import SVGs in a React and Vite app
In this article, I will share with you the different ways of importing SVGs in React, as well as how the process works...
Read more >The Best Way to Import SVGs in React
In this article, I will show the two methods to import SVG assets into React components. I like to call them the in-source...
Read more >How to use SVGs in React
Import it as a component via bundler magic (SVGR); Include it directly as JSX. Let's quickly go over each of them. Use SVGs...
Read more >How to import SVG files in React Native using ...
In rare cases, if you're not able to reference local SVGs using the <SvgUri> component, you can use XML strings to render SVGs...
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
Thanks for the investigation.
I’d expect it to be related to https://github.com/facebookincubator/create-react-app/pull/1305.