[英]Angular CLI SCSS File to Import not found or unreadable
Trying to import a variables.scss file and keep getting a build failed error:尝试导入 variables.scss 文件并不断收到构建失败错误:
ERROR in ./src/styles.scss (./node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js
!./node_modules/postcss-loader/src??embedded!./node_modules/sass-loader/lib/loader.js??ref--14-3!./src/styles.scss)
Module build failed (from ./node_modules/sass-loader/lib/loader.js):
undefined
^
File to import not found or unreadable: ~styles-variables.scss.
in C:\Users\JRYoung\Projects\ods\webclient\src\styles.scss (line 3, column 1)
In src/styles I have在 src/styles 我有
/* You can add global styles to this file, and also import other style files */
@import 'styles-variables.scss';
@import '~bootstrap/scss/bootstrap.scss';
$fa-font-path: "~font-awesome/fonts";
@import '~font-awesome/scss/font-awesome.scss';
In src/styles-variables.scss I have在 src/styles-variables.scss 我有
$grid-breakpoints: (
xs: 0,
sm: 576px,
md: 768px,
lg: 992px,
xl: 1200px
);
$accent-color: #006a55;
@import '~styles-variables.scss'
issues a build error whereas @import 'styles-variables.scss'
does not. @import '~styles-variables.scss'
发出构建错误,而@import 'styles-variables.scss'
不会。
Also, when I import the style-variables.scss in a style in another module, I have to use relative paths @import "../../../styles-variables.scss";
另外,当我在另一个模块的样式中导入 style-variables.scss 时,我必须使用相对路径@import "../../../styles-variables.scss";
in order for it to build.为了它的建立。 Its my understanding that the tilde should resolve it without having to include the paths.我的理解是波浪号应该解决它而不必包含路径。
It seems like the ~
is having problems resolving the path, but it does resolve for bootstrap and font-awesome.似乎~
在解析路径时遇到问题,但它确实解决了引导程序和字体真棒。 Any ideas on what I am doing wrong?关于我做错了什么的任何想法?
Angular CLI: 7.0.3
Node: 8.11.3
OS: win32 x64
Angular:
...
Package Version
----------------------------------------
@angular-devkit/architect 0.10.3
@angular-devkit/core 7.0.3
@angular-devkit/schematics 7.0.3
@schematics/angular 7.0.3
@schematics/update 0.10.3
rxjs 6.3.3
typescript 3.1.3
It seems there's an issue with Angular versions 6 and above with the tilde- see here Angular 6 及更高版本的波浪号似乎存在问题 - 请参阅此处
Instead, I'd recommend adding the following line to the build options for this project in your angular.json file:相反,我建议将以下行添加到 angular.json 文件中此项目的构建选项中:
"stylePreprocessorOptions": {
"includePaths": [
"./src/styles-variables.scss"
]
}
And then you should be able to just write:然后你应该可以只写:
@import "styles-variables"
at the top of all files using those variables with no problems.在使用这些变量的所有文件的顶部没有问题。
If you reach here with google search, make sure your file name is matching exactly ie case sensitive.如果您使用谷歌搜索到达此处,请确保您的文件名完全匹配,即区分大小写。
For me, it was building fine in my local but it was failing in pipeline.对我来说,它在我当地的建筑很好,但在管道中失败了。
you just write at the top :你只需在顶部写:
@import '../scss/vars';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.