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

libertie's avatar

Using SCSS with Jetstream Inertia

I'm sort of stumped trying to figure out how to use <style lang="scss"> in my Vue components. I'm working in Laravel 8 Jetstream Inertia and followed the instructions at https://vue-loader.vuejs.org/guide/pre-processors.html#sass. But when I run npm run dev it throws an ugly error: Module build failed (from ./node_modules/sass-loader/dist/cjs.js): SassError: expected "{".

SFC

<template> ... </template>
<script> ... </script>
<style lang="scss">
$color-green: #29a634;
body { background-color: $color-green; }
</style>

webpack.config.js

const path = require('path');

module.exports = {
    module: {
        rules: [
            {
                test: /\.scss$/,
                use: ['vue-style-loader', 'css-loader', 'sass-loader']
            }
        ]
    },
    resolve: {
        alias: {
            '@': path.resolve('resources/js'),
        },
    },
};

npm ls

├── @inertiajs/[email protected]
├── @inertiajs/[email protected]
├── @inertiajs/[email protected]
├── @tailwindcss/[email protected]
├── @tailwindcss/[email protected]
├── @vue/[email protected]
├── @vueform/[email protected]
├── @vueform/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Any advice would be greatly appreciated!

0 likes
14 replies
shaungbhone's avatar

Is it a manual install or with a starter kit? I mean inertia.

frankielee's avatar
Level 29

@libertie

I have tested at my end, using fresh installation Laravel and jetstream + inertia

All you need to do is executing the below command, rerun the command npm run dev.

npm install sass-loader sass webpack --save-dev

https://webpack.js.org/loaders/sass-loader/

Remove the custom config rules you added for SASS/SCSS. Webpacker 6 will provide the appropriate CSS rules for you

https://stackoverflow.com/questions/66216033/compiling-js-via-webpacker-results-in-sasserror-expected

2 likes
libertie's avatar

@frankielee Thanks! I had previously seen that Stack Overflow comment, but was confused by the reference to "Webpacker 6" (which is for Rails, not PHP). Turns out that removing the rules I copies from the vue-loader guide did the trick. How strange!

For anyone coming along after me, removing the rules didn't immediately resolve the issue. I also installed [email protected] and restarted npm run watch a few times :)

frankielee's avatar

@libertie Actually I don't recommend people to do this. Since you are using Inertia which is a Single Page Application. Which normally only refresh the content, not the entire page, so the scoped style wouldn't affect the whole page.

libertie's avatar

@frankielee Good point. The body styling above was just an example. My actual SCSS is specific to the component markup.

Please or to participate in this conversation.