由于 SassError: 找不到要导入的样式表,ng 测试失败 [英] ng test fails because of SassError: Can't find stylesheet to import
问题描述
我有几个 .scss
文件,我将这些文件导入到包含在模块中的组件中.当我为 dev 或 prod 构建我的项目时,一切都很好,但是当我运行 ng test
时,我看到一堆错误,内容如下:
I have several .scss
files that I import in my components which are contained within modules. When I build my project for dev or for prod everything is fine, but when I run ng test
I see a bunch of errors saying something like:
SassError: SassError: Can't find stylesheet to import.
1 │ @import "mixins";
我的模块中每个导入的 .scss
文件都会发生这种情况.共享样式放置在 src/assets/styles
目录中,如下所示:
This happens for every imported .scss
file in my modules. Shared styles are placed in src/assets/styles
directory like this:
-src
-assets
-styles
-_mixins.scss
-_theme.scss
...etc
在我的 angular.json
中,我有以下属性:
In my angular.json
I have the following properties:
"styles": ["src/styles.scss"],
"stylePreprocessorOptions": {
"includePaths": ["src/assets/styles"]
},
我尝试在主 style.scss
中引用我的所有样式,但无济于事.困扰我的主要事情是在开发和生产模式下一切正常,只是测试带来了这些错误,我想不出解决这个问题的方法.
I've tried referencing all my styles in main style.scss
, but to no avail. The main thing that buggers me is that in dev and prod mode everything works fine, it's just the tests that bring these errors and I can't figure a way to fix this.
Angular version is 10.0.5
Sass version is 1.26.5
Sass loader version is 8.0.2
推荐答案
这个问题已经回答了好几次了.也请使用搜索和投票来回答问题.
This question has been answered several times already. Please also use the search and vote for questions and answers.
On Stackoverflow: 1 2 3
在 Github 上的 AngularCLI 上:1
On the AngularCLI on Github: 1
修复此导入并添加到预处理器.
使用此补丁projects.NAME.architect.test
更新您的angular.json
文件
Update your angular.json
file in the patch projects.NAME.architect.test
with this
"styles": ["src/styles.scss"],
"stylePreprocessorOptions": {
"includePaths": ["src/assets/styles"]
},
这篇关于由于 SassError: 找不到要导入的样式表,ng 测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!