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

importing svg breaks component in production. #2669

Closed
CoachThomLamb opened this issue Jun 28, 2017 · 5 comments
Closed

importing svg breaks component in production. #2669

CoachThomLamb opened this issue Jun 28, 2017 · 5 comments

Comments

@CoachThomLamb
Copy link

Ok first time posting an issue so be kind :)

Node version 7.9
npm 4.2
yarn 0.20.3
react scripts 0.9.5
Mac mac sierra ox10.12.3

When I run in development my app works fine, however when I switch to production any component that has an SVG like this:

import SvgIcon from './svgIcon.svg'
returns with the following error.

https://facebook.github.io/react/docs/error-decoder.html?invariant=105&args[]=HardwareSmartphone

When I remove the svg and replace with a png the component renders fine.

Please let me know if I need to answer anything else ?

@gaearon
Copy link
Contributor

gaearon commented Jun 28, 2017

Please fill the issue template. There is too little information to help you. We'll need an example reproducing the issue.

@CoachThomLamb
Copy link
Author

CoachThomLamb commented Jun 28, 2017

Is this a bug report?

No this is a question about inlined svgs that is not answered in the issue docs or the user guide.

Can you also reproduce the problem with npm 4.x?

I am using npm 4.2

Which terms did you search for in User Guide?

I read over the adding images fonts and files section after searching "svg" as well as "valid react element".
Then I read issue #1180 which says that svgs never get inlined.
So if I manually add the svg to the build directory the component stops breaking when I'm serving the bundle using express.

My question is - is there a way to automatically pull all svgs into the build directory instead of doing it manually ? Because I have material UI components that have svgs embedded within them and I'm not easily able to find and place them in the build directory ?
I feel like I am just missing something very obvious, but I have been searching the user guide for a few days.

Environment

Add an svg inlined to a react component like so

import svgIcon from './svg_icon.svg'

then run yarn run build and yarn run serve.

Expected behaviour

teh svg should be pulled into the build directory. I understand that issue #1180 created an exception for svgs to not be inlined. What is not obvious to me from looking at the user guide and the issue comments is WHAT do we do when we want svgs to be loaded into the list of static assets, bc at this time they are not being loaded at all.

Actual Behavior

If I run yarn run build and yarn run serve, the componet with the inline svg will fail to load and return an error 105. If I then manually add the svg into the build directory, then the component does render.

@CoachThomLamb
Copy link
Author

#2065 this sounds very similar to what I am experiencing.

@CoachThomLamb
Copy link
Author

Closing this, I've upgraded to 1.08. However external svgs from other component libraires are still not loading, however I'll do more reading to see if this has been solved. Thanks @gaearon !

@gaearon
Copy link
Contributor

gaearon commented Jun 28, 2017

Sorry, what I meant is that we couldn't help you without a project reproducing it (last section of the issue template). Glad to hear it's working in latest version!

@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

2 participants