Search code examples
node.jssassnode-sass

Cannot compile scss file through sass module


I need a map of initial values, so I'm using this

spacer.scss

@use "sass:map";

$initial: 4px;

$values: ();

@for $i from -5 through 12 {
  $spacers: map.sets($spacers, $i, $i * $spacer);
}

Using sass module for compiling


const result = sass.compile('./spacer.scss');

But it throws an error while compiling

  ╷
7 │   $spacers: map.sets($spacers, $i, $i * $spacer);
  │             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵

Solution

  • You have a typo in your scss file.

    map.sets is not a map function.

    use map.set instead

    @use "sass:map";
    
    $initial: 4px;
    
    $values: ();
    
    @for $i from -5 through 12 {
      $spacers: map.set($spacers, $i, $i * $spacer);
    }