79489906

Date: 2025-03-06 15:52:00
Score: 0.5
Natty:
Report link

Solution for Fixing Sass Import in Vite 3

Install sass if It's Not Installed

If sass is missing from your project, install it using:

npm install sass --save-dev

Fix the Path in vite.config.js

In vite.config.js, change the additionalData option to use the alias @ instead of ./src/...:

import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/assets/scss/_variables.scss" as *;`
      }
    }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
})

Restart the Vite Development Server

npm run dev

Key Points:

✔ Use @use "@/assets/scss/_variables.scss" as *; instead of @import, since @import is deprecated in Dart Sass 3.0.0+.

✔ Ensure the path starts with @/ instead of ./src/, which might not be resolved correctly by Vite.

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @use
  • User mentioned (0): @import
  • User mentioned (0): @import
  • Low reputation (1):
Posted by: LEONARDO HERNANDEZ