Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't import SVG components from external packages #2236

Closed
stepankuzmin opened this issue May 19, 2017 · 12 comments
Closed

Can't import SVG components from external packages #2236

stepankuzmin opened this issue May 19, 2017 · 12 comments

Comments

@stepankuzmin
Copy link

stepankuzmin commented May 19, 2017

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

@gaearon
Copy link
Contributor

gaearon commented May 19, 2017

Sounds like a bug. Did it work before?

@stepankuzmin
Copy link
Author

Yep, it works fine with 0.9.5.

@gaearon
Copy link
Contributor

gaearon commented May 19, 2017

Cool. Want to dig into it? I'll have time later today but there are more pressing bugs which I'll likely look at first.

@stepankuzmin
Copy link
Author

Yep, I'm trying to investigate this bug. This works fine with local SVG components, only external packages are facing it, btw.

@gaearon
Copy link
Contributor

gaearon commented May 19, 2017

I’d expect it to be related to #1305.

@Timer
Copy link
Contributor

Timer commented May 19, 2017

This looks more like intended functionality than a bug. We don't compile node_modules (you're using JSX syntax).

0.9.x used webpack 1 which did not support jsmain:next or module properties, which are now respected (so 0.9.x grabs dist/main.js, 1.0.0 src/index.js).

You'll need to fix @urbica/components by compiling it during publish; checkout babel-preset-react-app!

Thanks!

@Timer Timer closed this as completed May 19, 2017
@stepankuzmin
Copy link
Author

Thanks for response @Timer! Removing module and jsnext:main did the trick

@gaearon
Copy link
Contributor

gaearon commented May 19, 2017

Thanks for the investigation.

tlvince added a commit to tlvince/create-react-app that referenced this issue Jun 6, 2017
This crops up in the form of uglify errors during a production build, e.g. facebook#2236, facebook#2433, facebook#2475. The suggestion there is to transpile deps down to ES5 and/or remove `module`. However, `module` is there specifically to indicate ES module support, which uglify doesn't support, so ask webpack not to resolve it.
@WillowHQ
Copy link

I'm experiencing a similar problem, can @Timer or @stepankuzmin add a bit more detail. How did you get the external module to compile ?

@Timer
Copy link
Contributor

Timer commented Jun 28, 2017

@WillowHQ, the package that needed changed was controlled by @stepankuzmin. It was not a 3rd party package.

I suggest you open an issue on the repository you're having issues with and ask them to fix their build so that it may be consumed by browsers. 😄

@WillowHQ
Copy link

it's material- ui and I believe I've found the solution.
Is there any point in documenting this anywhere once I solve ?

@Timer
Copy link
Contributor

Timer commented Jun 28, 2017

If the solution is generic enough, sure! We could document it here.
If it's specific to material-ui, maybe a PR to their docs would be better suited?

@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants