Skip to content
Latchkey

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.

sass
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

  1. Identify the two modules that reference each other.
  2. Extract the shared variables or mixins into a third partial both can @use.
  3. Remove the back-reference so the graph is acyclic, then rebuild.
styles/_tokens.scss
// _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 @use between two stylesheets.
  • Use @forward for re-exports instead of circular @use.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →