Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

giperib162's avatar

Laravel mix not compiling scss files

Hi, I just started learning Laravel and I've got a good understanding of routes, views, and layouts. my problem is with compiling assets and especially scss, I'm trying to set up laravel mix to compile my scss when I make a change and run npm run watch i get that nothing is wrong but nothing changes. does anyone can help me with this, please? It's been two days and I'm still having this problem, I've tried everything but nothing works. (I've tried deleting node_modules and run npm install it doesn't work)

My webpack.mix.js looks like this:

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

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css');
0 likes
32 replies
Sinnbeck's avatar

How do you compile assets? Using npm run dev? What is the content of app.scss?

giperib162's avatar

I've compiled them using npm run dev and using npm run watch and run watch-poll and nothing works some bootstrap classes not working either like "well" class the content of the app.sccss

// Body
$body-bg: #0000; // I've tested with the bg color and it won't change

// Typography
$font-family-sans-serif: 'Nunito', sans-serif;
$font-size-base: 0.9rem;
$line-height-base: 1.6;

// Colors
$blue: #3490dc;
$indigo: #6574cd;
$purple: #9561e2;
$pink: #f66d9b;
$red: #e3342f;
$orange: #f6993f;
$yellow: #ffed4a;
$green: #38c172;
$teal: #4dc0b5;
$cyan: #6cb2eb;
Sinnbeck's avatar

You are just setting a bunch of variables? Did you mean to import bootstrap?

Add this underneath

@import "~bootstrap/scss/bootstrap";
1 like
giperib162's avatar

I didn't even begin setting my own variables and my own project (I'm still learning), I can't start if scss won't compile and I've imported bootstrap on my app.scss file

// Fonts
@import url('https://fonts.googleapis.com/css?family=Nunito');

// Variables
@import 'variables';

// Bootstrap
@import '~bootstrap/scss/bootstrap';
Sinnbeck's avatar

Well start from something simple and work your way up.

Add this to your app.scss as the only thing

body {
    background: red !important;
} 

Now compile and check the content of your /public/css/app.css file

giperib162's avatar

It gives me the same thing on my /public/css/app.css file

body { background: red !important; }

1 like
Sinnbeck's avatar

Congratulations. You just successfully compiled your first scss file. Now you can try adding the import for bootstrap and recompiling. See if the css file changes

giperib162's avatar

Now I've added the font and the variables only, it gave me just the font on the app.css file

Sinnbeck's avatar

As it should. A variable cannot be compiled to anything. Only used.

For example

$blue: #3490dc; 
body {
    background: $blue;
}
Sinnbeck's avatar

That is why you import bootstrap, and compile it yourself. So you can override their variables

giperib162's avatar

Okay, I've imported bootstrap and now the variables don't work, for example, I changed the background color to black but on the website it's not black, plus some bootstrap classes doesn't work either

Sinnbeck's avatar

Please post what you have currently. And don't move your own variables to another file until you know it works. And what classes does not work?

giperib162's avatar

I have a big app.css file with many selectors and elements (i think that what bootstrap did) I've tried to put a sidebar into a well so I've changed its class to "well" but it doesn't work

Sti3bas's avatar

@giperib162 npm install bootstrap.

app.scss:

// Fonts
@import url('https://fonts.googleapis.com/css?family=Nunito');

// Variables
@import 'variables';

// Bootstrap
@import '~bootstrap/scss/bootstrap';

https://github.com/laravel/ui/blob/2.x/src/Presets/bootstrap-stubs/app.scss

_variables.scss:

// Body
$body-bg: #f8fafc;

// Typography
$font-family-sans-serif: 'Nunito', sans-serif;
$font-size-base: 0.9rem;
$line-height-base: 1.6;

// Colors
$blue: #3490dc;
$indigo: #6574cd;
$purple: #9561e2;
$pink: #f66d9b;
$red: #e3342f;
$orange: #f6993f;
$yellow: #ffed4a;
$green: #38c172;
$teal: #4dc0b5;
$cyan: #6cb2eb;

https://github.com/laravel/ui/blob/2.x/src/Presets/bootstrap-stubs/_variables.scss

giperib162's avatar

My files are exactly like these. the problem is when I try and change $body-bg: #000000 it won't work for some reason

Sinnbeck's avatar

Can you show how you are importing all your css files in your blade file?

giperib162's avatar

of course, I'm importing them like this <link rel="stylesheet" href="css/app.css">

giperib162's avatar

I've tried different browsers and even changed servers I've used XAMMP and MAMP

Sinnbeck's avatar

Please add, ``` on the line before and after your code to format it. You can just edit the post

Sinnbeck's avatar

Is that the only css you are importing. You aren't importing other libs, or perhaps bootstrap?

Also either use the asset helper, or prefix with a slash before css

<link rel="stylesheet" href="/css/app.css">
giperib162's avatar

That's the only one I'm importing, here's the whole header

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Test</title>
    <link href="css/app.css" rel="stylesheet">
</head>
giperib162's avatar

if I use it this way with a slash before <link rel="stylesheet" href="/css/app.css"> the css don't work

Sinnbeck's avatar

What is the root of your website? It should be /

You can use the asset helper

<link rel="stylesheet" href="{{asset('css/app.css') }}">  

Is you variables.scss file prefixed with underscore? _variables.scss

giperib162's avatar

I don't understand what you mean by the root of my website sorry, but i access my website via localhost/mywebsite/public

and yes my variables.css is prefixed with an underscore

Sinnbeck's avatar

Ok it seems your webserver isn't correctly configured. Just leave it for now. Use the asset helper and set the url in env file.

Sadly I am out of ideas for now

giperib162's avatar

I've tried the asset helper and it didn't do anything, but thanks anyway.

I'll try to search how to configure my server maybe that will help, thanks again

cariboufute's avatar

I notice myself that Laravel Mix doesn't compile SCSS files when using lazy loading in routes with vue-router. When using static loading (import X from 'x'), SCSS compiling works again!

I don't know yet why it is so. Have you tried this?

Next

Please or to participate in this conversation.