sass loader error while building the project

huangapple go评论144阅读模式
英文:

sass loader error while building the project

问题

I get the below error while building my project:

 Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
 SassError: 2 arguments required, but only 1 was passed.
    ╷
         width: rem(300);
                ^^^^^^^^

I am sure rem(300) is a valid syntax. Can you please tell me why the build is throwing this error?

英文:

I get he below error while building my project

 Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
 SassError: 2 arguments required, but only 1 was passed.
    ╷
         width: rem(300);
                ^^^^^^^^

Below is my package.json

{
  "name": "test",
  "version": "3.0.0",
  "private": true,
  "scripts": {
   
  },
  "devDependencies": {
    "mini-css-extract-plugin": "^2.4.2",
    "node-sass": "^6.0.1",
    "postcss": "^8.3.9",
    "postcss-loader": "^6.2.0",
    "postcss-preset-env": "^6.7.0",
    "sass": "^1.3",
    "sass-loader": "^12.1.0"
  },
  "dependencies": {
   
    "grunt-sass": "^3.1.0"
    
  }

}

I am sure rem(300) is a valid syntax. Can you please tell me why the build is throwing this error

答案1

得分: 7

CSS rem() 函数需要两个参数:https://developer.mozilla.org/en-US/docs/Web/CSS/rem

> rem() CSS 函数在第一个参数除以第二个参数后返回剩余的余数,类似于JavaScript的余数运算符(%)。

如果您创建了一个自定义的rem()函数,我建议将其命名为其他名称,以避免可能的冲突。

英文:

The CSS rem() function required 2 parameters: https://developer.mozilla.org/en-US/docs/Web/CSS/rem

> The rem() CSS function returns a remainder left over when the first
> parameter is divided by the second parameter, similar to the
> JavaScript remainder operator (%)

If you created a custom rem() function, I suggest naming it something else as there could be a conflict.

答案2

得分: 7

遇到了同样的问题,今天我在我的 package.json 中有 "sass": "^1.26.5"。

昨天 sass 更新到了 1.65.1,你的构建应该可以使用 1.64.2。
https://www.npmjs.com/package/sass/v/1.65.1?activeTab=versions
我遇到了这个问题是因为另一个我无法控制的依赖项,所以暂时改变 sass 版本是唯一的选择。但如果你在自己的代码中使用了 rem(),请参考 Ali Klein 的回答。

英文:

Ran into the same problem today, I had "sass": "^1.26.5" in my package.json.

sass got updated yesterday to 1.65.1, your build should work with 1.64.2
https://www.npmjs.com/package/sass/v/1.65.1?activeTab=versions
I got that problem due to another dependency I have no control over, so changing sass version was the only option for now. But if you used rem() in your own code, go for Ali Klein's answer.

答案3

得分: 3

更新到版本1.65.0后,保留的calc函数出现了。这些函数调用将被解析为Sass计算,而不是函数调用:round()、mod()、rem()、sin()、cos()、tan()、asin()、acos()、atan()、atan2()、pow()、sqrt()、hypot()、log()、exp()、abs()或sign()。以其中任何一个命名的用户自定义函数将不能再无命名空间地调用。

正如您所看到的,rem()不再能作为自定义函数。将其更名,一切都会像以前一样工作。

进入链接描述页面

英文:

After updating css to version 1.65.0, reserved calc functions appeared. These function calls will be analyzed as sass calculations instead of function calls: round(), mod(), rem(), sin(), cos(), tan(), asin(), acos(), atan(), atan2(), pow(), sqrt(), hypot(), log(), exp(), abs() or sign(). User-defined functions named after any of them can no longer be called without a namespace.

As you can see, rem() can no longer be a custom function. Change its name and everything will work as before.

enter link description here

huangapple
  • 本文由 发表于 2023年8月11日 01:53:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76878223.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定