You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular中Sass的@use指令在组件样式文件中失效的问题咨询

Angular中Sass的@use指令在组件样式文件中失效的问题咨询

我目前在Angular项目里搭配WebStorm使用Sass开发,遇到了一个关于@use指令的问题,想请教大家:

  • 首先,在根目录下的custom-theme.scss文件中,我写了这样的代码:

    @use "@angular/material" as mat;
    

    完全没有报错,项目运行和样式编译都正常。

  • 但是当我在组件的样式文件dialog.component.sass里,尝试导入上面的自定义主题时:

    @use "../../../../styles/custom-theme" as customTheme
    

    立刻就抛出了编译错误,具体错误信息如下:

    cmd.exe /D /C call C:\Users\user\AppData\Roaming\npm\sass.cmd --load-path ../node_modules dialog.component.sass:dialog.component.css
    Error: Can't find stylesheet to import.
      ╷
    1 │ @use "@angular/material" as mat;
      │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      ╵
      ..\..\..\..\styles\custom-theme.scss 1:1  @use
      dialog-error.component.sass 1:1           root stylesheet
    
    Process finished with exit code 65
    
  • 另外,在根目录的styles.sass文件中,我用@use "styles/custom-theme" as theme导入自定义主题,同样没有任何问题。

我给Sass和SCSS设置的编译参数都是:--load-path ../node_modules $FileName$:$FileNameWithoutExtension$.css

实在搞不懂,为什么根目录的样式文件能正常处理这种导入,到了组件的样式文件里,自定义主题里的@use "@angular/material"就找不到对应的样式表了呢?

备注:内容来源于stack exchange,提问作者xRay

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.17 10:12:58