components icon indicating copy to clipboard operation
components copied to clipboard

Not able to compile custom theme

Open skined90 opened this issue 9 years ago • 40 comments

I'm not able to set the custom material theme like in Theming your Angular Material app guide.

When I add the scss code like in the sample:

@import '~@angular/material/core/theming/all-theme';
// Plus imports for other components in your app.

// Include the base styles for Angular Material core. We include this here so that you only
// have to load a single css file for Angular Material in your app.
@include md-core();

// Define the palettes for your theme using the Material Design palettes available in palette.scss
// (imported above). For each palette, you can optionally specify a default, lighter, and darker
// hue.
$candy-app-primary: md-palette($md-indigo);
$candy-app-accent:  md-palette($md-pink, A200, A100, A400);

// The warn palette is optional (defaults to red).
$candy-app-warn:    md-palette($md-red);

// Create the theme object (a Sass map containing all of the palettes).
$candy-app-theme: md-light-theme($candy-app-primary, $candy-app-accent, $candy-app-warn);

// Include theme styles for core and each component used in your app.
// Alternatively, you can import and @include the theme mixins for each component
// that you are using.
@include angular-material-theme($candy-app-theme);

When I run node-sass, I'm getting the error:

{ "status": 1, "file": "/home/skined/workspace/project/src/scss/style.scss", "line": 5, "column": 1, "message": "File to import not found or unreadable: ~@angular/material/core/theming/all-theme\nParent style sheet: /home/skined/workspace/project/src/scss/style.scss", "formatted": "Error: File to import not found or unreadable: ~@angular/material/core/theming/all-theme\n Parent style sheet: /home/skined/workspace/project/src/scss/style.scss\n on line 5 of src/scss/style.scss\n>> @import '~@angular/material/core/theming/all-theme';\n ^\n" }

Am I doing something wrong?

skined90 avatar Dec 19 '16 10:12 skined90

AFAIK the ~ prefix on the import is the notation used for importing in Webpack. If you're not using Webpack, you have to import the file directly.

crisbeto avatar Dec 19 '16 11:12 crisbeto

@crisbeto I'm using a webpack.

skined90 avatar Dec 19 '16 11:12 skined90

Weird. You can try importing @import '~@angular/material/core/theming/_all-theme';. Technically it shouldn't make a difference, but it's worth a shot.

crisbeto avatar Dec 19 '16 11:12 crisbeto

@crisbeto Did it also, but it doesn't work.

skined90 avatar Dec 19 '16 11:12 skined90

try without ~, you could also try to set up --include-path

fxck avatar Dec 19 '16 12:12 fxck

@fxck I already tried. It doesn't work. It works for other libraries but with material does not.

skined90 avatar Dec 19 '16 13:12 skined90

I am had the same issue. I replaced ~ with ../node_modules/, it seems to be reading the file fine now but another issues arose.

{
  "status": 1,
  "file": "/home/jason/Projects/project-tracker/node_modules/@angular/material/core/_core.scss",
  "line": 4,
  "column": 1,
  "message": "It's not clear which file to import for '@import \"overlay/overlay\"'.\nCandidates:\n  overlay/overlay.scss\n  overlay/overlay.css\nPlease delete or rename all but one of these files.\n",
  "formatted": "Error: It's not clear which file to import for '@import \"overlay/overlay\"'.\n       Candidates:\n         overlay/overlay.scss\n         overlay/overlay.css\n       Please delete or rename all but one of these files.\n        on line 4 of node_modules/@angular/material/core/_core.scss\n>> @import 'overlay/overlay';\n   ^\n"
}

woowe avatar Dec 19 '16 19:12 woowe

@skined90 I am using webpack and I didn't face any issue while importing. See the code below:

@import './../node_modules/@angular/material/core/theming/all-theme';

Based on your app structure you can adjust the path to locate node_modules.

faisalmuhammad avatar Dec 24 '16 01:12 faisalmuhammad

@faisalmuhammad thanks for the workaround. I also had the same issue. Using webpack as well with "angular-cli": "1.0.0-beta.22-1", "@angular/material": "^2.0.0-alpha.11-3",

dasis avatar Jan 04 '17 01:01 dasis

We haven't been able to reproduce this issue. Feel free to open a new issue if you are able to provide a full reproduction.

jelbourn avatar Jan 27 '17 03:01 jelbourn

Have same issue

Dunky13 avatar Feb 06 '17 19:02 Dunky13

Hi everybody I have same problem . any idea ?

hashemnik avatar Feb 16 '17 11:02 hashemnik

@Dunky13 @hashemnik All styling things begin now with "mat".

Look at the updated theming guide: https://github.com/angular/material2/blob/master/guides/theming.md

dahaupt avatar Feb 16 '17 18:02 dahaupt

Hi everybody Finally I solved my problem. I replaced @angular/material": "^2.0.0-beta.2", with @angular/material": "2.0.0-beta.1", In package.json file. And it work fine.

hashemnik avatar Feb 21 '17 03:02 hashemnik

Having exactly the same problem... Any ideas?

using, webpack: 2.2.0 @angular/material: 2.0.0-beta.2 (tried 2.0.0-beta.1 but nothing changed)

onurcipe avatar Mar 08 '17 16:03 onurcipe

This issue certainly exists ("webpack": "2.2.1") However, @import './../node_modules/@angular/material/core/theming/all-theme'; worked for me.

Looks like you'll have to point directly to the all-theme file.

BenRacicot avatar Mar 19 '17 01:03 BenRacicot

@BenRacicot already tried, doesn't solve the issue. Many also reported that pointing all-theme file doesn't solve the issue for them.

Using,

"dependencies": {
    "@angular/common": "2.4.7",
    "@angular/compiler": "2.4.7",
    "@angular/compiler-cli": "2.4.7",
    "@angular/core": "2.4.7",
    "@angular/forms": "2.4.7",
    "@angular/http": "2.4.7",
    "@angular/material": "2.0.0-beta.2",
    "@angular/platform-browser": "2.4.7",
    "@angular/platform-browser-dynamic": "2.4.7",
    "@angular/platform-server": "2.4.7",
    "@angular/router": "3.4.7",
    "@angular/upgrade": "2.4.7",
    "bcrypt-nodejs": "0.0.3",
    "body-parser": "1.16.1",
    "core-js": "2.4.1",
    "express": "4.14.1",
    "hammerjs": "2.0.8",
    "hbs": "4.0.1",
    "jsonwebtoken": "7.3.0",
    "mongoose": "4.8.3",
    "mongoose-unique-validator": "1.0.3",
    "reflect-metadata": "0.1.9",
    "rxjs": "5.1.1",
    "zone.js": "0.7.2"
  },
  "devDependencies": {
    "@ngtools/webpack": "1.2.4",
    "@types/core-js": "0.9.35",
    "@types/hammerjs": "2.0.34",
    "@types/node": "7.0.5",
    "angular2-router-loader": "0.3.5",
    "angular2-template-loader": "0.6.2",
    "awesome-typescript-loader": "2.2.4",
    "del-cli": "0.2.1",
    "node-sass": "4.5.0",
    "raw-loader": "0.5.1",
    "sass-loader": "6.0.2",
    "typescript": "2.1.1",
    "webpack": "2.2.0",
    "webpack-merge": "2.6.1"
  }

onurcipe avatar Mar 19 '17 18:03 onurcipe

@onurcipe are you using a scss compiler? The compilation told me that there was an error trying to import that file because it didn't exist at that path. I had to look into the node_modules/@angular/material/ folders to find the real path and corrected my path.

Side note. It does seem that most online stuff is misleading. 💥 Either pointing to Material for ng1 or the use of md on css which has been changed to mat- to name a few. :boom: Seems like we're in the really early stages for Angular 2x Material...

BenRacicot avatar Mar 19 '17 20:03 BenRacicot

@BenRacicot I am using "sass-loader": "6.0.2" and when I import all-theme as you did this time the AoT compiler cannot find core which is in the second line of all-theme as @import '../core';.

It is obvious that online documents are not up to date. Unfortunately at the moment, we should read the changelog.

By the way, for the ones who are facing the similar issues like I do, currently the only solution is to import these two lines and customize it in your css file. <link href="https://unpkg.com/@angular/material/core/theming/prebuilt/indigo-pink.css" rel="stylesheet"> <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

onurcipe avatar Mar 19 '17 20:03 onurcipe

@onurcipe I had that issue too (I think) did you use @include mat-core()? Many sources say to include @include md-core() which is apparently deprecated...?

BenRacicot avatar Mar 19 '17 20:03 BenRacicot