我正面临着我的Angular 项目的问题,在使用sass-Loader进行编译期间,sass文件会产生错误.错误消息特别说明:

Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
semicolons aren't allowed in the indented syntax.

这些错误出现在引用Imports和@use指令的多个SASS文件中,例如styles.sasstheming/theme.sass.这些错误似乎与sass缩进语法中的分号有关.

以下是有问题的SASS文件的一些示例片段:

styles.sass

@import 'theme.sass';

theming/theme.sass

@use '@angular/material' as mat;

$theme-palette: (
    50 : #f4e6e5,
    100 : #e3bfbf,
    200 : #d19595,
    300 : #bf6b6a,
    400 : #b14b4a,
    500 : #a32b2a,
    600 : #9b2625,
    700 : #91201f,
    800 : #881a19,
    900 : #77100f,
    A100 : #ffabaa,
    A200 : #ff7877,
    A400 : #ff4644,
    A700 : #ff2d2a,
    contrast: (50 : #000000,
        100 : #000000,
        200 : #000000,
        300 : #000000,
        400 : #ffffff,
        500 : #ffffff,
        600 : #ffffff,
        700 : #ffffff,
        800 : #ffffff,
        900 : #ffffff,
        A100 : #000000,
        A200 : #000000,
        A400 : #ffffff,
        A700 : #ffffff,
    )
);

@include mat.core();

// Define your primary, accent, and warn colors
// Define your primary palette using the provided colors
$theme-primary: mat.define-palette($theme-palette, 500);

// Define the accent and warn palettes (adjust colors as needed)
$theme-accent: mat.define-palette($theme-palette, 'A200', 'A100', 'A400');
$theme-warn: mat.define-palette($theme-palette, 'A400', 'A200', 'A700');

// Define the custom theme
$custom-theme: mat.define-light-theme((color: (primary: $theme-primary,
                accent: $theme-accent,
            ),
            typography: mat.define-typography-config(),
            density: 0,
        ));

// Register the theme with Angular Material
@include mat.all-component-themes($custom-theme);

Full Logs

✔ Browser application bundle generation complete.

Initial Chunk Files | Names         |  Raw Size
vendor.js           | vendor        |   6.33 MB |
polyfills.js        | polyfills     | 333.18 kB |
styles.js           | styles        | 239.31 kB |
main.js             | main          |  22.31 kB |
runtime.js          | runtime       |   6.53 kB |

                    | Initial Total |   6.92 MB

Build at: 2024-01-06T07:32:24.510Z - Hash: 31ab0a294b3109b4 - Time: 14282ms

./src/styles.sass - Error: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
semicolons aren't allowed in the indented syntax.
  ╷
1 │ @import 'theme.sass';
  │                     ^
  ╵
  src\styles.sass 1:21  root stylesheet

./src/theming/theme.sass - Error: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
semicolons aren't allowed in the indented syntax.
  ╷
1 │ @use '@angular/material' as mat;
  │                                ^
  ╵
  src\theming\theme.sass 1:32  root stylesheet

./src/styles.sass?ngGlobalStyle - Error: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
HookWebpackError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):      
semicolons aren't allowed in the indented syntax.
  ╷
1 │ @import 'theme.sass';
  │                     ^
  ╵
  src\styles.sass 1:21  root stylesheet

./src/theming/theme.sass?ngGlobalStyle - Error: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
HookWebpackError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):      
semicolons aren't allowed in the indented syntax.
  ╷
1 │ @use '@angular/material' as mat;
  │                                ^
  ╵
  src\theming\theme.sass 1:32  root stylesheet

推荐答案

请将文件名改为scss而不是sass我认为这是问题的根本原因

您可以运行该命令来执行此操作!

ng set defaults.styleExt sass

article

如果您仍然面临这个问题,您也可以try 将文件重命名为sass

Angular相关问答推荐

to Signal on Observables inside Signal

存储服务存储在本地存储中,但无法检索到它

将输入传递到组合Angular指令

为什么在回调完成之前,可观察对象会返回?

在Angular 应用中混合使用较少和较粗俗的文件

如何在Primeng中实现自定义排序

出错后可观察到的重用

Angular 9表单构建器 - 日期验证器问题

如何从2个api获取数据并查看Angular material 表中的数据?

Angular 迁移 14 到 15 / 16:angular universal 是否停止将 <!-- this page was prerendered with angular universal --> 用于预渲染页面?

如何将模块导入独立指令

应该显示在表格中的嵌套循环

为什么 AngularFire .set() 永远等待响应并且不继续?

Renderer2.appendChild 没有按预期工作?

如何在 Angular 2 模板中使用枚举

Angular 7 测试:NullInjectorError:No provider for ActivatedRoute

读取文件并解析其内容

Angular2 - 如何开始以及使用哪个 IDE

如何从 EventEmitter 函数返回值?

如何使用formControlName和处理嵌套的formGroup?