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.

Production build not load svg

See original GitHub issue

Hello, I have a problem with svg. This is my steps:

  1. run ng build --prod --base-href /my/app/ (it compiles the application into an dist directory)
  2. load dist directory on server
  3. navigate the app from browser
  4. not show svgs

Locally with ng serve it works namely it shows all the svg. I see that in dist directory there are all the svg. This is the code in template:

<div class="wrapper-img">
     <img src="./assets/img/name.svg" class="img-responsive"/>
</div>

To clarify, I don’t have this problem with png or jpg. How can I fix it? Thanks.

Versions.

@angular/cli: 1.2.1 node: 6.10.1 os: win32 x64 @angular/animations: 4.4.4 @angular/cli: 1.2.1 @angular/common: 4.4.4 @angular/compiler: 4.4.4 @angular/compiler-cli: 4.4.4 @angular/core: 4.4.4 @angular/forms: 4.4.4 @angular/platform-browser: 4.4.4 @angular/platform-browser-dynamic: 4.4.4 @angular/router: 4.4.4 @angular/language-service: 4.4.4

Repro steps.

  1. Run --> ng build prod --base-href ./
  2. Load content in dist folder on apache

Desired functionality.

  1. See svg

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
alan-agius4commented, Sep 18, 2018

Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular CLI version.

If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.

2reactions
Corsicocommented, Dec 18, 2017

Can be reproduced with ie11-, svgs set as backgrounds in css become encoded and have a style tag that breaks the behavior on ie.

initial scss

background-image: url('some/path.svg');

result with -prod build

background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg id='Layer_1' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cstyle%3E.st0 {fill:%23ccc;}%3C/style%3E%3Cpath class='st0' fill='%23ccc' d='M0 13.5V16h2.5L13.9 4.6l-2.5-2.4L0 13.5zM15.7 2.7c.3-.2.3-.7 0-.9L14.2.3c-.2-.3-.7-.3-.9 0l-1.2 1.2L14.6 4l1.1-1.3z' id='edit_2_'/%3E%3C/svg%3E");

expected result

background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg id='Layer_1' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath class='st0' fill='%23ccc' d='M0 13.5V16h2.5L13.9 4.6l-2.5-2.4L0 13.5zM15.7 2.7c.3-.2.3-.7 0-.9L14.2.3c-.2-.3-.7-.3-.9 0l-1.2 1.2L14.6 4l1.1-1.3z' id='edit_2_'/%3E%3C/svg%3E");

Could be the way the svg is saved, or how the scripts handle this. Not sure as of yet.

Example of issue on codepen https://codepen.io/anon/pen/RxrMjB

Read more comments on GitHub >

github_iconTop Results From Across the Web

svg's won't load in production mode - angular - Stack Overflow
All my svg's work perfectly in dev mode, as soon as I run `ng build --prod --aot" they are not loading. They all...
Read more >
How to Load SVG with React and Webpack | Pluralsight
The solution is not farfetched. We'll need the help of another awesome webpack loader called svgr, which, according to the website, transforms ...
Read more >
react-svg - npm
A React component that injects SVG into the DOM.. Latest version: 15.1.17, last published: 2 days ago. Start using react-svg in your project ......
Read more >
How To Import SVGs into NextJS | Frontend Digest
In this error, webpack is telling us that it doesn't have a loader set up to handle this particular file type (.svg files)....
Read more >
The Best Way to Import SVGs in React - Better Programming
Who doesn't appreciate the coolness that SVG brings? ... And the output in create-react-app is the build folder in production and the development...
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