Angular 4 + Material 2 SASS compilation error "File to import not found or unreadable"

I am trying to use a custom theme, but I keep getting the error:

{
  "status": 1,
  "file": "/home/adam/Projects/test-material/src/unicorn.scss",
  "line": 1,
  "column": 1,
  "message": "File to import not found or unreadable: ~@angular/material/theming.\nParent style sheet: /home/adam/Projects/test-material/src/unicorn.scss",
  "formatted": "Error: File to import not found or unreadable: ~@angular/material/theming.\n       Parent style sheet: /home/adam/Projects/test-material/src/unicorn.scss\n        on line 1 of src/unicorn.scss\n>> @import '~@angular/material/theming';\n   ^\n"
}

I installed brandy new Angular to test it and I keep getting the same error. I tried:

$ ng new test-material
$ cd test-material/
$ npm install --save @angular/material

Then I created a file with a name src/unicorn.scssand inserted a sample custom theme from https://material.angular.io/guide/theming and tried to compile it using: $ node-sass src/unicorn.scss dist/unicorn.css I got the above error. Content unicorn.scss:

@import '~@angular/material/theming';
@include mat-core();
$candy-app-primary: mat-palette($mat-indigo);
$candy-app-accent:  mat-palette($mat-pink, A200, A100, A400);
$candy-app-warn:    mat-palette($mat-red);
$candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent, $candy-app-warn);
@include angular-material-theme($candy-app-theme);

I am using Angular 4 and Material 2.0.0-beta.3. This is my .json package:

{
  "name": "test-material",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^4.0.0",
    "@angular/compiler": "^4.0.0",
    "@angular/core": "^4.0.0",
    "@angular/forms": "^4.0.0",
    "@angular/http": "^4.0.0",
    "@angular/material": "^2.0.0-beta.3",
    "@angular/platform-browser": "^4.0.0",
    "@angular/platform-browser-dynamic": "^4.0.0",
    "@angular/router": "^4.0.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.1.0",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@angular/cli": "1.0.0",
    "@angular/compiler-cli": "^4.0.0",
    "@types/jasmine": "2.5.38",
    "@types/node": "~6.0.60",
    "codelyzer": "~2.0.0",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",
    "karma": "~1.4.1",
    "karma-chrome-launcher": "~2.0.0",
    "karma-cli": "~1.0.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "protractor": "~5.1.0",
    "ts-node": "~2.0.0",
    "tslint": "~4.5.0",
    "typescript": "~2.2.0"
  }
}
+4
source share
3 answers

2.0.0-beta.3 '~@angular/material/theming';

node_modules/@angular/material, , _theming.scss, :

@import '~@angular/material/_theming';

:

sass-loader v6.0.4 : .scss @import '~@angular/material/_theming.scss'; sass-loader v6.0.5 .scss

+2

.angular-cli.json:

"stylePreprocessorOptions": {
    "includePaths": [
        "../node_modules"
    ]
},
+2

, . :
customTheme.scss src.

@import '../node_modules/@angular/material/_theming';

@include mat-core();

$candy-app-primary: mat-palette($mat-cyan);
$candy-app-accent:  mat-palette($mat-green, A200, A100, A400);
$candy-app-warn:    mat-palette($mat-red);
$candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent, $candy-app-warn);
@include angular-material-theme($candy-app-theme);

: import angular, customTheme.scss.


:
customTheme.scss .angular-cli.json

styles": [
        "styles.css",
        "theme.scss"
      ],
+2
source

Source: https://habr.com/ru/post/1674598/


All Articles