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.

Can't import SVG components from external packages

See original GitHub issue

Can 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

  1. npm ls react-scripts (if you haven’t ejected):
velobike@0.3.0 /Users/stepan/projects/velobike
└── react-scripts@1.0.0 
  1. node -v: 7.10.0

  2. npm -v: 4.6.1

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

github_iconTop GitHub Comments

1reaction
gaearoncommented, May 19, 2017

Thanks for the investigation.

1reaction
gaearoncommented, May 19, 2017
Read more comments on GitHub >

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

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