Sass says a mixin is undefined although the file defines it
SassError: 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.
Fix it fast
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 -302Match what you see, then jump to its fix
- 1
The mixin is loaded in main.scss, but the error points at a component stylesheetThe failing file never loads the mixin fileFix - 2
@use "mixins" is present, but the call is a bare @include rounded@include is missing the namespace that @use createdFix - 3
The mixin is called -rounded or _rounded and sits in another fileThe mixin name starts with a hyphen or underscoreFix - 4
Old files use @import, new ones use @use, and some stylesheets lose names@import is mixed with @use and the mixin is not globalFix
- 1
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.scss2Fix
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 buildConfirmed by sass-lang.com
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 -202Fix
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 buildConfirmed by sass-lang.com
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 buildConfirmed by sass-lang.com
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/ | head2Fix
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 buildConfirmed by sass-lang.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
Related fixes
Web apps
Dart Sass warns that the legacy JS API will be removed
Warning appears on every build after updating sass to 1.79.0 or newer
The warning means a tool in your build still calls Dart Sass through its old render or renderSync functions.
2 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fix