9

In my angular 6 app I have the following in my scss file:

.pictureplaceholder{
  background-image: url("assets/images/profilepictureplaceholder/PersonPlaceholder.png");
}

that is the correct path to the resource. yet I get this error.

ERROR in ./src/app/venueadmin/parentadminview/venueuserprofile/venueuserprofile.component.scss
(Emitted value instead of an instance of Error) CssSyntaxError: /home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/frontend/fixedsuitsandtables/src/app/venueadmin/parentadminview/venueuserprofile/venueuserprofile.component.scss:11:20: Can't resolve 'assets/images/profilepictureplaceholder/PersonPlaceholder.png' in '/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/frontend/fixedsuitsandtables/src/app/venueadmin/parentadminview/venueuserprofile'

   9 | 
  10 | .pictureplaceholder{
> 11 |   background-image: url('assets/images/profilepictureplaceholder/PersonPlaceholder.png');
     |                    ^
  12 | }
  13 | 

My other images that are in the assets folder are working. Very strange. Anyone know what this is?

weridpotato
  • 261
  • 1
  • 3
  • 11

6 Answers6

22

Add a / to the beginning of each URL.

background-image: url("/../assets/images/profilepictureplaceholder/PersonPlaceholder.png");

based on your directory hierarchy adjust your relative path. But add a forward slash at the beginning.

For more info refer

Zoe
  • 27,060
  • 21
  • 118
  • 148
leox
  • 1,315
  • 17
  • 26
5

got it. It was a relative path without the ""

so

background-image: url(../../../../assets/images/profilepictureplaceholder/PersonPlaceholder.png);
weridpotato
  • 261
  • 1
  • 3
  • 11
2

We can use relative path instead of absolute path:

$assetPath: '~src/assets/images/';
$logo-img: '#{$assetPath}logo.png';
@mixin logo {
  background-image: url(#{$logo-img});
}

.logo {
    max-width: 65px;
    @include logo;
 }
Aarji George
  • 599
  • 4
  • 8
1

use in this way

$asset-images-path : "assets/images/imagePathHere";
background-image: image-url("#{$asset-images-path}/imageNameWithExtension.png");
dasunse
  • 2,839
  • 1
  • 14
  • 32
0

URL might not be right:

url('/./assets/images/bike.jpg');
Marcin Bach
  • 51
  • 1
  • 2
0

I have tried all the above-mentioned methods but this worked for me

#imge6{
    background-image: url("../../../../assets/5.png");
    background-size: cover;
}

maybe solve someone else's problem.

Saad Abbasi
  • 745
  • 11
  • 25