Skip to content

Angular 12 : Loading svg using url(../../assets/images/app_logo.svg) is not working in Scss #20882

Closed
@ngdevelop-tech

Description

@ngdevelop-tech

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Yes, the previous version in which this bug was not present was: Angular 10

Description

Recently I have created a new application using angular 12 in which I am getting the following bug,

I am using SVG image as background: url('../../assets/images/app_logo.svg') no-repeat; in auth.component.scss file, When I do any changes in this file it renders it in the first load properly but when I do any changes in other files, it is not able to get the image and gives GET http://localhost:4200/app_logo.svg 404 (Not Found).

During this time I am getting the following error in the console
image

Previously it was working in angular 10.
I have checked these #18115, #18013, #18041 and #18043 related issues but not found any proper solution.

🔬 Minimal Reproduction

In AppComponent template add one div and load any svg file from assets in that div as background

<!-- app.component.html -->
<div class="root"></div>
// app.component.scss
.root{
    background: url('../assets/images/app_logo.svg') no-repeat;
    height: 200px;
}

Serve your application, when you save changes in app.component.scss it will render the image properly. Now update anything in any other file let's take in app.component.html, Now when an application is reloaded it will not show the logo SVG image.

🔥 Exception or Error

image

🌍 Your Environment





Angular CLI: 12.0.1
Node: 12.17.0
Package Manager: npm 6.14.4
OS: win32 x64

Angular: 12.0.1
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, material, platform-browser, platform-browser-dynamic
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1200.1
@angular-devkit/build-angular   12.0.1
@angular-devkit/core            12.0.1
@angular-devkit/schematics      12.0.1
@schematics/angular             12.0.1
rxjs                            6.6.7
typescript                      4.2.4

Anything else relevant?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions