Sass "Module loop: ... already being loaded" in CI
The Sass module system forbids circular @use chains. "Module loop: this module is already being loaded" means file A uses B while B (directly or transitively) uses A, which has no defined evaluation order.
What this error means
The Sass build fails with "Error: Module loop: this module is already being loaded." naming the file at the point the cycle closes.
Error: Module loop: this module is already being loaded.
+-> src/styles/theme.scss
| @use 'colors';
| ^^^^^^^^^^^^^^^Common causes
Two modules @use each other
A direct cycle (theme uses colors, colors uses theme) cannot be loaded in a single order, so Sass rejects it.
A transitive cycle through shared partials
A longer chain of @use eventually loops back to a module already on the load stack.
How to fix it
Break the cycle with a shared base module
- Identify the two modules that reference each other.
- Extract the shared variables or mixins into a third partial both can
@use. - Remove the back-reference so the graph is acyclic, then rebuild.
// _tokens.scss holds shared values
// theme.scss and colors.scss both @use 'tokens';Use @forward for re-exports
If one module only needs to expose another's members, @forward instead of @use to flatten the graph and avoid a loop.
How to prevent it
- Keep shared tokens in a leaf partial that other modules
@use. - Avoid mutual
@usebetween two stylesheets. - Use
@forwardfor re-exports instead of circular@use.