You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SVG Files are not included in the dev bundle. #2065
SVG files fail to be included in the development bundle.
This occurs when the image is imported like so: import Logo from '../../common/img/logo.svg';
and used like so: <img src={Logo} />
Other image files (.png, .jpg, etc) render as expected, but SVG files never come through.
Expected behavior
SVG images should load as normal.
Actual behavior
Renders as a broken <img /> tag. When the URL to the image, as output by Webpack, is entered into the URL bar, it renders this error: "error on line 1 at column 1: Document is empty".
Environment
Node version 7.9.0
NPM version 4.2.0
Windows 10 | Version 1703 | OS Build 15063.0
Google Chrome | 58.0.3029.81 (64-bit)
Reproducible Demo
Due to some time constraints, I can't make a demo at the moment. If you can't reproduce this issue let me know and I'll try to get a demo up.
@gaearon@alisonmonteiro Alright, I've got a demo you can look at. You'll notice the header image is a broken link, and if you look at the actual file, it's been stripped down to a single line of code:
I don't know that my employer would love if I shared the whole source, but I could probably share some of the files. Which files do you think would be most useful?
Yeah, everything is inside of src. I ejected so that I could add SASS to the Webpack pipeline, but that's the only alteration. How can I check what version of react-scripts I was on?
It would really help if you could try reproducing this in a freshly created app, or trim down your app to the minimal amount files necessary to reproduce (and then share the runnable project).
I don't believe so, I only added the scss loader. I'm away from my computer, but I'll check through my commits to make sure I didn't paste over it on accident somewhere.
@existentialism No, I've checked my commits and I never added that piece. But it turns out that it's the piece that was breaking it. Removing that line seems to have fixed it.
Activity
alisonmonteiro commentedon May 4, 2017
@chrisjpatty how the
.svgfile looks like (the code)?gaearon commentedon May 4, 2017
A demo would help greatly.
chrisjpatty commentedon May 4, 2017
@alisonmonteiro Here is a sample of the SVG code. I've omitted the majority of the paths for the sake of brevity.
alisonmonteiro commentedon May 4, 2017
@chrisjpatty just copied your svg and saved as a file and:
no errors at all. 👍
As @gaearon said, a demo would help greatly.
chrisjpatty commentedon May 5, 2017
@gaearon @alisonmonteiro Alright, I've got a demo you can look at. You'll notice the header image is a broken link, and if you look at the actual file, it's been stripped down to a single line of code:
Hopefully this is what you need to troubleshoot this issue. Let me know what else I can provide and thank you for the help!
**Edit: ** Whoops, forgot to include the link: Broken SVG Demo
gaearon commentedon May 5, 2017
Sorry, where can we find the demo?
chrisjpatty commentedon May 5, 2017
@gaearon Sorry, forgot to paste it. Demo
gaearon commentedon May 5, 2017
Is it possible to also share the source?
chrisjpatty commentedon May 5, 2017
I don't know that my employer would love if I shared the whole source, but I could probably share some of the files. Which files do you think would be most useful?
gaearon commentedon May 5, 2017
The file that imports the SVG, the SVG file, and their exact locations in the source tree.
chrisjpatty commentedon May 5, 2017
Sure, I can do that. Here's an abbreviated sample of the structure:
And a zip folder containing
Shell.js,ND-Logo.svg, and my webpack config files.Broken SVG Files.zip
gaearon commentedon May 5, 2017
Is everything inside
srcfolder?gaearon commentedon May 5, 2017
Do you mean that you ejected? On which version of
react-scriptswere you on?chrisjpatty commentedon May 5, 2017
Yeah, everything is inside of
src. I ejected so that I could add SASS to the Webpack pipeline, but that's the only alteration. How can I check what version of react-scripts I was on?chrisjpatty commentedon May 5, 2017
I'm not sure how to check the version, but I used the tool on 4/17/2017 and ejected that very same day.
1 remaining item
chrisjpatty commentedon May 5, 2017
I actually ejected immediately unfortunately, so it doesn't show up in my initial commit.
chrisjpatty commentedon May 5, 2017
But if it's helpful, here is my full package.json at this point:
gaearon commentedon May 5, 2017
It would really help if you could try reproducing this in a freshly created app, or trim down your app to the minimal amount files necessary to reproduce (and then share the runnable project).
chrisjpatty commentedon May 5, 2017
I'll see what I can do. Thanks for your help so far!
chrisjpatty commentedon May 5, 2017
Got it! Here's a trimmed down version of the source that you can compile.
broken-svg-src.zip
gaearon commentedon May 5, 2017
Tagging as a bug and needing help. Would appreciate somebody looking into it!
existentialism commentedon May 5, 2017
@chrisjpatty did you add:
to your
webpack.config.dev.js?chrisjpatty commentedon May 5, 2017
I don't believe so, I only added the scss loader. I'm away from my computer, but I'll check through my commits to make sure I didn't paste over it on accident somewhere.
Timer commentedon May 5, 2017
I believe it's worth noting that you do not need to eject to use Sass, you can read how to do that in our docs.
chrisjpatty commentedon May 5, 2017
@existentialism No, I've checked my commits and I never added that piece. But it turns out that it's the piece that was breaking it. Removing that line seems to have fixed it.