Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found: Error: Can't resolve '../fonts/fontawesome-webfont.eot'

I am using Webpack 4 and installed "font-awesome": "^4.7.0" in package.json. Then I tried to import it into my index.scss as following:

@import '~font-awesome/scss/font-awesome.scss';
@import '~bootstrap/scss/bootstrap.scss';  

And I've got the following error message:

ERROR in ./src/index.scss (./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/index.scss)
    Module not found: Error: Can't resolve '../fonts/fontawesome-webfont.eot' in '/Volumes/Develop/react-reason/cockpit/src'
     @ ./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/index.scss 7:414-457

    ERROR in ./src/index.scss (./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/index.scss)
    Module not found: Error: Can't resolve '../fonts/fontawesome-webfont.eot?v=4.7.0' in '/Volumes/Develop/react-reason/cockpit/src'
     @ ./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/index.scss 7:332-383

    ERROR in ./src/index.scss (./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/index.scss)
    Module not found: Error: Can't resolve '../fonts/fontawesome-webfont.svg?v=4.7.0' in '/Volumes/Develop/react-reason/cockpit/src'
     @ ./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/index.scss 7:806-857

    ERROR in ./src/index.scss (./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/index.scss)
    Module not found: Error: Can't resolve '../fonts/fontawesome-webfont.ttf?v=4.7.0' in '/Volumes/Develop/react-reason/cockpit/src'
     @ ./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/index.scss 7:711-762

    ERROR in ./src/index.scss (./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/index.scss)
    Module not found: Error: Can't resolve '../fonts/fontawesome-webfont.woff2?v=4.7.0' in '/Volumes/Develop/react-reason/cockpit/src'
     @ ./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/index.scss 7:525-578

    ERROR in ./src/index.scss (./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/index.scss)
    Module not found: Error: Can't resolve '../fonts/fontawesome-webfont.woff?v=4.7.0' in '/Volumes/Develop/react-reason/cockpit/src'
     @ ./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./src/index.scss 7:619-671

As you can see, bootstrap works fine, but font-awesome not.
The folder of downloaded font-awesome looks as following: enter image description here

Do I miss some configuration?

Update Import the css file like:

@import '~font-awesome/css/font-awesome.css';

but import scss file like:

@import '~font-awesome/scss/font-awesome.scss';

does not work why?

like image 738
softshipper Avatar asked May 19 '18 08:05

softshipper


People also ask

How do I import Fortawesome Fontawesome for free?

OR you can import the module in your js code. import '@fortawesome/fontawesome-free/js/all. js'; OR if you are using Sass, you can import the module in app.

How do I use Font Awesome SCSS?

Adding Font Awesome to Your CompileOpen your project's scss/variables. scss and edit the $fa-font-path variable to point to where you placed the webfonts folder. $fa-font-path: "../webfonts"; In your main SCSS compile file, import Font Awesome by adding the core styles file, @import "scss/fontawesome.

Is Fortawesome free?

Font Awesome Free is free, open source, and GPL friendly. You can use it for commercial projects, open source projects, or really almost whatever you want.


3 Answers

Specify the font location before import :

$fa-font-path: "~font-awesome/fonts/";
@import "~font-awesome/scss/font-awesome";
like image 141
Emmanuel Bachschmidt Avatar answered Sep 22 '22 01:09

Emmanuel Bachschmidt


I made it work with these steps:

create src/_variables.scss with content:

$fa-font-path: '../node_modules/font-awesome-sass/assets/fonts/font-awesome/';

So I set the complete path beginning ../node_modules

and for completeness my src/styles.scss:

@import 'variables';
@import "../node_modules/font-awesome-sass/assets/stylesheets/font-awesome";

(I'm using package font-awesome-sass so your path(s) may differ)

like image 43
Matthias Burger Avatar answered Sep 24 '22 01:09

Matthias Burger


change it

$fa-font-path: "./webfonts";

for exemple (fontawesome 5):

$fa-font-path: "~@fortawesome/fontawesome-free/webfonts";

in app.scss

like image 2
Alan Limeira Brito Avatar answered Sep 23 '22 01:09

Alan Limeira Brito