Error 404 when loading resources from node_modules folder with Angular2

Asked

Viewed 208 times

0

I am with an application using angular 4 that is giving error 404 when trying to load resources css, fonts and javascript folder node_modules.

It’s like this on my index.html:

<link href="node_modules/font-awesome/css/font-awesome.min.css" />
<link href="node_modules/simple-line-icons/css/simple-line-icons.css" />
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" />
<link href="node_modules/bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.min.css" />

My angular-cli is updated and before I normally carried.

What I’ve been looking for, I read that I needed the setting "moduleResolution": "node" in tsconfig.json. It’s already there and it’s not working.

What should I do?

1 answer

0

To insert third party libraries as font awesome and bootstrap you must modify your file .angular-cli.json in your project for when the build project files are included.

    "styles": [
        "styles.css",
        "../node_modules/font-awesome/css/font-awesome.min.css",
        "../node_modules/simple-line-icons/css/simple-line-icons.css"
        "../node_modules/bootstrap/dist/css/bootstrap.min.css",
        "../node_modules/bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.min.css"
    ],
    "scripts": [
        "../node_modules/jquery/dist/jquery.js",
        "../node_modules/bootstrap/dist/css/bootstrap.min.css"
    ],

in your case add only in the field of style the paths of the archives css necessary for the project, and remove them from the index.html to leave the charge of angular insert these files.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.