angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Assets/Images not being served...

Open smatthews1999 opened this issue 8 years ago • 44 comments

Versions

Angular CLI: 1.6.6
Node: 6.9.4
OS: win32 x64
Angular: 5.2.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.6.6
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.6
@schematics/angular: 0.1.17
typescript: 2.5.3
webpack: 3.10.0

Repro steps

  1. add any image to /src/assets/images/
  2. reference image in HTML
  3. ng serve

Observed behavior

image is not found Request URL:http://localhost:4200/assets/images/logo.png Request Method:GET Status Code:404 Not Found

I have made sure that my angular-cli.json lists the assets folder... image Assets folder directly under src directory image HTML is typical

  <img src="./assets/images/logo.png"/>

Image is 404 image

Here is a minimal example... https://github.com/smatthews1999/testng

smatthews1999 avatar Mar 02 '18 17:03 smatthews1999

I am having the same problem :/ I tried with the latest version and still doesn't work!

YousraBenzeghiba avatar Mar 10 '18 01:03 YousraBenzeghiba

@smatthews1999 <img src="assets/images/ic_launcher.png"> It ran successfully for me.

luoguibin avatar Mar 22 '18 08:03 luoguibin

It's after the packs are updated npm update I can attach an icon

Alekcei avatar Apr 05 '18 15:04 Alekcei

Need verify package versions

Alekcei avatar Apr 05 '18 16:04 Alekcei

@smatthews1999 Try increasing the dimensions of the image in paint. I had an image in the path src/assets/Library/Images with dimensions 60 x 45 which did not load and an image with dimensions 225 x 225 which loaded successfully. Hope this helps !

pnklshh avatar Apr 09 '18 12:04 pnklshh

if img convert to base64? then his break in file system. Need verify css file

Alekcei avatar Apr 09 '18 13:04 Alekcei

@smatthews1999 Have u found out a solution to u'r problem, I face the same problem while I was trying to render the image, It was giving me the same error as 404 Not Found. I have tried alt+click on the path of the image and it took me to the image on my vscode. But don't know why it's not able find the image on browser. Anyone please help !!! Here is the version of angular cli and browser-platform angular cli version

avinashdv avatar Jun 08 '18 16:06 avinashdv

I am having the same issue,

Angular CLI: 6.0.8 Node: 8.11.2 OS: win32 x64 Angular: 6.0.4

aajmot avatar Jun 09 '18 20:06 aajmot

@aajmot I thought I should downgrade to 1.6.3 to overcome, Luckily found out a solution without downgrading, just remove all the symbols, brackets for all your folders starting from particular drive. If u'r project is in E drive follow below change this location

E:\Data\project - 1\Angular(learning)\app

to

E:\Data\project1\Angularlearning\app

U will be able to see the loaded assets folder to the browser under sources tab in chrome developer tools

avinashdv avatar Jun 10 '18 05:06 avinashdv

the way i have done it is by creating assets folder in each component and inside it created an images and then placed the images that are need for that particular component, then importing the images from same component folder and it works

muhammadumerfarooq avatar Jun 11 '18 08:06 muhammadumerfarooq

Can you try using the binding..

<img [src]="assets/images/ic_launcher.png">

aajmot avatar Jun 11 '18 10:06 aajmot

I tried the solution @avinashdv proposed and it worked. You need to make sure all the folders of your project's path have no : [] or "." in them my project was [BYCK][1.0] when I turned it into BYCK_10 it worked .

YousraBenzeghiba avatar Jun 11 '18 16:06 YousraBenzeghiba

I am still having this issues. There are no special characters in my file path except "_", image is inside assets/img folder. I see it in the dist for prod build, but local dev server isn't serving it up.

PTC-JoshuaMatthews avatar Jul 10 '18 15:07 PTC-JoshuaMatthews

Figured it out, apparently file names are case sensitive.

PTC-JoshuaMatthews avatar Jul 10 '18 16:07 PTC-JoshuaMatthews

@PTC-JoshuaMatthews Glad it helped

avinashdv avatar Jul 10 '18 16:07 avinashdv

Try increasing the width and height of the image. It worked for me

nibisha avatar Aug 02 '18 01:08 nibisha

Assets not loading after --prod build and then deployed to firebase? all styles font etc work, just not images?? assets folder only?? everything works fine on local server. All other projects deployed successfully in the past? this project is giving me grief! ng v 6.1.0 I have no errors???

alvics avatar Aug 14 '18 06:08 alvics

@alvics I'm getting same issues here. can't load images of assets folders properly when deployed to firebase. on local machine works perfects. Trying to solve this, but i think ill have to back to prior cli version.

paulimfavarato avatar Aug 15 '18 04:08 paulimfavarato

@paulimfavarato let me know how you go? I still trying! no luck, try some tests?? It use to be easy not sure what there doing with the CLI? :(

alvics avatar Aug 15 '18 05:08 alvics

@alvics no lucky yet. posted on stackoverflow too https://stackoverflow.com/questions/51853387/angular-6-build-cant-load-images-on-firebase-hosting

paulimfavarato avatar Aug 15 '18 05:08 paulimfavarato