问题描述
我正在尝试使用 Karma 在我的 Angular 应用程序中运行前端单元测试。但是我无法编译测试,在控制台中运行“ng test”时它失败并显示以下错误消息:
Error: Module build Failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Can't find stylesheet to import.
╷
1 │ @use 'internal-library' as *;
│ ^^^^^^^^^^^^^^^^^^^^^^
╵
../../../src/styles/global.scss 1:1 @import
../../../src/styles/styles.scss 8:9 root stylesheet
如何从 karma 中排除编译样式表?或者我应该尝试其他解决方案吗?
回复:第一条评论,我按照其他答案的建议更新了我的 angular.json,如下:
"styles": [
"src/styles/styles.scss"
],"stylePreprocessorOptions": {
"includePaths": [
"src/styles"
]
},
(适应我的文件结构)
-src
-styles
-global.scss -> here's the import it's struggling with
-styles.scss -> the global file is then imported here
-api
-mixins.scss
-variables.scss
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)