Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Sass says a mixin is undefined although the file defines it

ErrorSassError: Undefined mixin.

Short answer

Sass only sees a mixin that the current file loads. With @use, every stylesheet needs its own @use line, and the mixin is called with its namespace, such as corners.rounded. Names that start with a hyphen or underscore stay private to their file. Load the mixin file in the failing stylesheet and call it by the right name.

  • Applies to Dart Sass 1.80+, sass-loader (current release), React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the stylesheet named in the error and look at the top. Does it load the file that defines the mixin, and does the @include match the way it was loaded?

    grep -rn "@mixin" src/ | head
    grep -rn "@use\|@import\|@forward" src/ | head -30
  2. 2Match what you see, then jump to its fix

    1. 1The mixin is loaded in main.scss, but the error points at a component stylesheetThe failing file never loads the mixin fileFix
    2. 2@use "mixins" is present, but the call is a bare @include rounded@include is missing the namespace that @use createdFix
    3. 3The mixin is called -rounded or _rounded and sits in another fileThe mixin name starts with a hyphen or underscoreFix
    4. 4Old files use @import, new ones use @use, and some stylesheets lose names@import is mixed with @use and the mixin is not globalFix

What does the error look like?

  • SassError: Undefined mixin.
  • Module build failed (from ./node_modules/sass-loader/dist/cjs.js)

Cause 1 of 4

The failing file never loads the mixin file

1Check

Members loaded with @use are visible only in the stylesheet that loads them. A second file does not inherit them, even when both end up in the same bundle.

head -5 src/components/Button.module.scss

2Fix

Add a @use rule to the file that includes the mixin. @use must come before any style rules. To share one entry point, create a file that @forwards the others and @use that file.

// Button.module.scss
@use "../styles/mixins";

.button {
  @include mixins.rounded;
}

3Verify

Restart the dev server (or rebuild) and check the stylesheet compiles.

npm run build

Confirmed by sass-lang.com

Did this fix it?

Cause 2 of 4

@include is missing the namespace that @use created

1Check

@use gives members a namespace, which defaults to the file name without its extension. A call without that prefix does not find the mixin.

grep -rn "@include" src/ | head -20

2Fix

Prefix the call with the namespace, choose a shorter one with as, or load with as * for a stylesheet you own.

@use "../styles/mixins" as m;
.card { @include m.rounded; }

// or, no prefix at all:
@use "../styles/mixins" as *;
.card { @include rounded; }

3Verify

Rebuild and confirm the error is gone.

npm run build

Confirmed by sass-lang.com

Did this fix it?

Cause 3 of 4

The mixin name starts with a hyphen or underscore

1Check

Names that begin with - or _ work only inside the file that defines them, so loading that file from another stylesheet cannot reach them. Sass also treats hyphens and underscores in mixin names as identical.

grep -rn "@mixin [-_]" src/

2Fix

Rename the mixin without the leading character, and update every @include.

// before
@mixin _rounded { border-radius: 4px; }
// after
@mixin rounded { border-radius: 4px; }

3Verify

Rebuild the project.

npm run build

Confirmed by sass-lang.com

Did this fix it?

Cause 4 of 4

@import is mixed with @use and the mixin is not global

1Check

@import makes everything in the imported file global, while @use does not. Dart Sass deprecated @import in 1.80.0 and will remove it in 3.0.0.

grep -rn "@import" src/ | head

2Fix

Move the file that defines the mixin to @use in every stylesheet that needs it, instead of relying on a global import elsewhere.

@use "../styles/mixins";

3Verify

Rebuild with no @import left for that file.

npm run build

Confirmed by sass-lang.com

Did this fix it?

How do I stop it coming back?

  • Treat every stylesheet as standalone: it loads what it uses.
  • Keep shared mixins in one folder and expose them through one forwarding file.
  • Do not start shared mixin names with - or _.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.