-1

I'm trying to get a svg image from a package in node_modules, I installed from my private local npm registry, the package downloaded and exists under my node_modules of the project, my html code is like this

<img src="/src/assets/images/my-image.svg">

as I use a little script in angular-cli.json file to pass assets from node_modules to this local assets folder. and I have the "Failed to load resource: the server responded with a status of 404 (Not Found)" I verified that the image exists on node_modues and I can preview it, i'm using angular/cli 1.6.8

Update:

Angular doesn't access assets on node_modules folder, but I find a way how to do it, by using this code:

"assets": [
    { "glob": "**/*",
      "input": "../node_modules/my-private-package.assets/",
      "output": "./assets/" },
    "assets",
    "favicon.ico"
  ]

In the angular-cli.json, but still cannot access these assets and still says same error.

getName
  • 693
  • 1
  • 9
  • 19

3 Answers3

2

The node_modules folder is for dependencies, not assets (like an svg) that you are using in your application.

Try putting the image file in the assets folder then link to it like this:

<img src="/assets/my-image.svg">

I.E. when you run ng build, the angular CLI will compile your files in a dist folder. Notice the assets folder is in there. The node_modules folder is not.

Kyle Krzeski
  • 6,183
  • 6
  • 41
  • 52
1

I found the issue with your source. node_modules is outside of the src folder. It should be ../node_modules. try below code,

<img src="../node_modules/my-private-packages/images/my-image.svg">
Hitesh Kansagara
  • 3,308
  • 3
  • 17
  • 32
0

Here is the best way to get the image.

<div>
    <img src="assets/images/dashboard.svg">
</div>