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 also getting the same error ... and on looking under networks tab found the following difference between the type of my two separate .png images. Both images have the same size and I am adding them in the html file as

<img class="img-thumbnail rounded mr-3 anim-zoomin" style="width:40%;height:auto" src="assets/images/image.png" alt="Generic placeholder image">

image

Does anyone have an idea of what does this mean? or how could I resolve it ?

mukherj avatar Mar 19 '19 22:03 mukherj

I've run into the same issue I think and posted on stack here: angular-8-assets-not-loading and was told to update this thread (hope that's ok :-) ).

Basically check the full path, I had parenthesis in mine and that stopped the assets from working.

  • myTestApp2 => works
  • 'my test' => works
  • 'my test(12)' => doesn't work

Hope it helps someone !

jorv83 avatar Jun 24 '19 13:06 jorv83

For anyone still having this issue, this was fixed it for me:

Open your tsconfig.json file (It is in the top level of your workspace directory).

Change this: "outDir": "./dist/out-tsc",

to this: "outDir": "./dist"

This answer was gotten from https://stackoverflow.com/a/56206651 where you can see the rest of it.

Chizaram-Igolo avatar Aug 14 '19 14:08 Chizaram-Igolo

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.