简体   繁体   English

未找到或无法读取要导入的 Angular CLI SCSS 文件

[英]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.对我来说,它在我当地的建筑很好,但在管道中失败了。

  1. scss: your folder name which is store your all scss files. scss:您的文件夹名称,用于存储您的所有 scss 文件。
  2. vars: your scss file name vars:你的 scss 文件名

you just write at the top :你只需在顶部写:

@import '../scss/vars';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到导入文件或不可读文件:SCSS - File to import not found or unreadable: SCSS Angular Webpack正在添加引导程序…[错误]找不到导入文件或文件不可读:../bootstrap/scss/_pager - Angular Webpack Adding Bootstrap … [Error] File to import not found or unreadable: ../bootstrap/scss/_pager 角度:找不到导入文件或不可读:〜css-star-rating / scss / star-rating - Angular: File to import not found or unreadable: ~css-star-rating/scss/star-rating Angular 4 + Material 2 SASS编译错误“要导入的文件未找到或不可读” - Angular 4 + Material 2 SASS compile error “File to import not found or unreadable” @Import scss、相对路径、angular-cli - @Import scss, relative path, angular-cli 用于跳过创建 SCSS 文件的 Angular CLI 命令 - Angular CLI command to skip creating the SCSS file .SCSS文件中的数学计算Angular CLI无法正常工作 - Mathematical Calculations In .SCSS file Angular CLI Is not Working Angular,Bootstrap 4,angular-cli-在哪里放置相关的scss并将其导入? - Angular, Bootstrap 4, angular-cli - where to place dependent scss and import it? webpack 错误:未找到要导入的文件或无法读取的文件:bourbon ,如何解决? - webpack error: File to import not found or unreadable: bourbon , how to fix? 未找到或无法读取要导入的文件:@material/button/mdc-button - File to import not found or unreadable: @material/button/mdc-button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM