1

I am trying to add package css file into my app.scss but it doesn't work,

Code

app.scss

@import '~tjdbs4/tjdb4.css';

webpack.mix.js

let mix = require('laravel-mix');

mix.js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css');

when I run npm run watch it works successfully but the style doesn't add to app.css

any idea?

Update

this is my complete app.scss file

// Fonts
@import url("https://fonts.googleapis.com/css?family=Raleway:300,400,600");

// Variables
@import "variables";

// Bootstrap
@import '~bootstrap/scss/bootstrap';
@import '~bootstrap-vue/dist/bootstrap-vue.css';
@import '~@fortawesome/fontawesome-free/scss/brands';
@import '~@fortawesome/fontawesome-free/scss/regular';
@import '~@fortawesome/fontawesome-free/scss/solid';
@import '~@fortawesome/fontawesome-free/scss/fontawesome';
@import '~tjdbs4/tjdb4';



.navbar-laravel {
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

when I use @import '~tjdbs4/tjdb4'; and run npm run watch command I get:

ERROR  Failed to compile with 2 errors                                                                                                  22:53:58
 error  in ./resources/assets/sass/app.scss

Module build failed: ModuleNotFoundError: Module not found: Error: Can't resolve '../webfonts/fa-brands-400.eot' in

but if i use @import '~tjdbs4/tjdb4.css'; and run npm run watch it doesn't show any error and also will not mix my css file with the rest of them.

4
  • Is the css file path wrong? You can try add a simple file, the path is same with app.scss. Commented Sep 11, 2018 at 4:16
  • @lighter no ~ will get node_modules folder Commented Sep 11, 2018 at 4:17
  • I use this // Bootstrap @import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";. It's work for me. Commented Sep 11, 2018 at 4:19
  • @lighter updated. Commented Sep 11, 2018 at 16:00

3 Answers 3

1

Since webpack is correctly resolving @import '~tjdbs4/tjdb4.css'; without splitting out a 'css-loader' error, it's likely you need to burst your browser cache.

You can fix this by versioning your compiled assets. Read more here.

  1. Make these changes in the webpack.mix.js file to turn on versioning.

    mix.js('resources/assets/js/app.js', 'public/js') .sass('resources/assets/sass/app.scss', 'public/css') .version();

  2. Now run npm run watch again.

    This will result in a new file mix-manifest.json being created under the public folder.

  3. Then modify your blade template as follows

    <link rel="stylesheet" href="{{ mix('/css/app.css') }}"> <script src="{{ mix('/js/app.js') }}"></script>

Sign up to request clarification or add additional context in comments.

Comments

1

You should be able to get this to work by removing the extension from the path:

@import '~tjdbs4/tjdb4';

3 Comments

unfortunately it doesn't work, i updated my question.
@mafortis If you run npm run dev from a new tab, wait for it to finish and then scroll back up, can you confirm there are definitely no errors? Is this a public or private package by the way?
definitely no error ibb.co/iYPXEp , so far is public. npmjs.com/package/tjdbs4
0

Your error seemed to be an issue with FontAwesome fonts and specifically the brands icon set from them.


This whole chunk here in app.scss

@import '~@fortawesome/fontawesome-free/scss/brands';
@import '~@fortawesome/fontawesome-free/scss/regular';
@import '~@fortawesome/fontawesome-free/scss/solid';
@import '~@fortawesome/fontawesome-free/scss/fontawesome';

should be placed inside your main js file like the following


Example

app.js

import brands from '@fortawesome/fontawesome-free-brands'
import regular from '@fortawesome/fontawesome-free-regular'
import solid from '@fortawesome/fontawesome-free-solid'
import fontawesome from '@fortawesome/fontawesome'

fontawesome.library.add(brands)
fontawesome.library.add(regular)
fontawesome.library.add(solid)

6 Comments

@mafortis you are missing a from
I realized that and tried with different ways it seems is not allowed to be in app.js file as they are styles they must be load in app.scss file
What is the error? I personally am importing FontAwesome into .js file and it worked
Hold up, I see something potentially wrong with the package path. Let me confirm that and get back to you
The error refers to imported files as i shared image. Ps: for other ways i tried errors almost same
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.