【发布时间】:2021-08-23 17:17:05
【问题描述】:
我需要在我的 Angular 应用程序中使用 Sass math.div 函数。这是我的 SCSS 代码示例:
@use "sass:math";
div {
min-height: math.div(100, 2);
}
我使用ng new my-application 命令创建了角度应用程序。我还使用ng generate library my-lib 命令在应用程序中创建了一个库。
带有math.div 的SCSS 代码在库中运行良好。如果我将 SCSS 代码放入 projects/my-lib/src/lib/my-lib.component.scss 并运行 ng build my-lib 则库将成功构建。
但是,如果我将 SCSS 代码放在 src 文件夹中,例如 src/app/app.component.scss 并运行命令 ng build,则会出现此错误:
Error: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Undefined function.
╷
4 │ min-height: math.div(100, 2);
│ ^^^^^^^^^^^^^^^^
╵
src\app\app.component.scss 4:17 root stylesheet
math.div function is available in sass since 1.33.0,所以我认为问题在于 Angular 应用程序由于某种原因与 Angular lib 具有不同的 sass 版本。但我不知道如何解决它。
例如 min-height: math.pow(10, 2); 在应用程序中运行良好。 math.pow is available since 1.25.0
【问题讨论】:
-
我遇到了类似的问题,这与我的 Node 版本过时有关。只需在命令行中运行
nvm use node(或更新节点)即可将 Node 提升到 Dart sass 期望能够使用math.div()的最新版本。