Home > Software engineering >  Deprecation Warning: Using / for division outside of calc() is deprecated and will be removed in Dar
Deprecation Warning: Using / for division outside of calc() is deprecated and will be removed in Dar

Time:02-25

In this function I compile rem to px and em to px.

$base: 16 !default;
    
    @function scut-strip-unit ($num) {
      @return $num / ($num * 0   1);
    }
    
    @function rem ($pixels) {
      @return scut-strip-unit($pixels) / $base * 1rem;
    }
    @function em ($pixels, $context: $base) {
        @return #{$pixels/$context}em;
      }

But in new update sass 1.49, we are facing this error:

    Error
    Deprecation Warning: Using / for division outside of calc() is deprecated and will be removed in Dart Sass 2.0.0.
    
    Recommendation: math.div(scut-strip-unit($pixels), $base) or calc(scut-strip-unit($pixels) / $base)
    
    More info and automated migrator: https://sass-lang.com/d/slash-div
    
      ╷
    8 │   @return scut-strip-unit($pixels) / $base * 1rem;

CodePudding user response:

What they are saying is that you should be using the math.div from sass:math to make divisions. You could do it this way (notice the @use "sass:math";):

@use "sass:math";

@function to-rem($pxNb) {
    @return math.div($pxNb, 16) * 1rem;
}


@function scut-strip-unit ($num) {
  @return math.div($num, ($num * 0   1));
}


@function rem ($pixels) {
  @return math.div(scut-strip-unit($pixels),($base * 1rem));
}
@function em ($pixels, $context: $base) {
    @return #{math.div($pixels,$context)}em;
  }
  • Related