Sass @use Migration: Diagnosing Duplicated CSS and Module Errors
Migrate from Sass @import to @use by diagnosing duplicated CSS, namespace conflicts, and deprecated function usage. Follow this diagnostic guide to identify and fix common migration issues.
23 Jun 2026, 10:01 UTC

The Problem: Duplicated CSS After Adopting @use
When migrating from Sass’ legacy @import to the modern @use module system, you may encounter duplicated CSS rules, module already loaded errors, or undefined variable/function messages. These issues typically stem from mixing @import and @use, or from incorrect namespace handling.
Root Cause: @import vs @use Behavior
| Feature | @import | @use |
|---|---|---|
| Execution | Re-executes file on every call | Executes module once |
| Namespace | Global (pollutes scope) | Scoped under namespace |
| Variable defaults | Can be overwritten | Loads once, !default respected |
Key insight: @import shares one global namespace across all files, while @use loads each module exactly once and scopes its members.
Diagnostic Checklist
- Search for remaining
@importstatements
Run in project root:
If found in entry files, they’re likely causing duplication.grep -r "@import" src/ --include="*.scss" - Verify built-in function usage
Check for legacy globals likedarken(),mix(), ordiv(). Under@use, these must be accessed via modules (e.g.,color.adjust(),math.div()). - Check variable definitions without
!default
Variables set in multiple imported files can cause conflicts. Look for:$primary: #007bff; // No !default - will override - Inspect namespace usage
Find un-namespaced references to colors, spacing, or typography that may now be scoped.
Fixes Based on Findings
Duplicate CSS Rules
If your output contains repeated selectors, ensure each partial is loaded through a single @use in a manifest file, then @forwarded:
// _index.scss (manifest)
@forward "variables";
@forward "mixins";
// main.scss (entry)
@use "./styles/index" as *;
Undefined Variables or Functions
After migration, add explicit @use of defining modules:
// Before (global access)
$primary: #007bff;
color: darken($primary, 10%);
// After (scoped)
@use "variables" as v;
@use "sass:color";
$primary: v.$primary;
color: color.adjust(v.$primary, $lightness: -10%);
Third-Party Dependencies Still Using @import
If vendor libraries rely on @import, isolate them:
// _legacy.scss
@import "vendor/mixins";
@import "vendor/functions";
// main.scss
@use "legacy" as legacy;
@use "new-module";
Escalation Criteria
- Compiler version mismatch: LibSass is deprecated and may not fully support
@use. Verify you’re using Dart Sass 1.23+. - Build tool integration: If your bundler (Webpack, Vite, etc.) uses an older Sass loader, update to a version supporting the module system.
- Complex dependency chains: If multiple libraries conflict, consider creating a compatibility layer with explicit
@forwardrules.
Verification Steps
- Compile a minimal entry file:
Check output for duplicated// test-entry.scss @use "styles/index" as *; @use "sass:color"; body { color: color.adjust(red, $lightness: 20%); }bodyrules. - Run Sass with warnings enabled:
Listen for deprecation notices aboutsass --no-source-map --style=expanded src/main.scss out.css@importor global functions. - Use trace mode for load order:
Confirm modules load once and in expected order.sass --trace src/main.scss out.css 2>&1 | head -20
Limitations and Considerations
- Dart Sass vs LibSass: LibSass reached end-of-life in 2021. Full
@usesupport requires Dart Sass. - Division operator: The
/syntax for division is deprecated. Usemath.div($a, $b)fromsass:math. - Rule ordering:
@userules must appear before any style rules or@importstatements, or compilation fails.
Quick Reference: Common Migration Patterns
| Before (@import) | After (@use) |
|---|---|
@import 'variables'; | @use 'variables'; |
darken($color, 10%) | color.adjust($color, $lightness: -10%) |
mix($a, $b, 50%) | color.mix($a, $b, $weight: 50%) |
10px / 2 | math.div(10px, 2) |
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.