Skip to content

Error Setting Up Custom Material Theme in Angular-CLI Project #5370

@darrenbrett

Description

@darrenbrett

My development environment:
/cli: 1.0.0-beta.31
node: 7.4.0
os: darwin x64

I am using material2 elements throughout my Angular 2 app, but would now like to be able to control the colors used for those elements. To do so I am trying to set up a custom theme to use. So far, no luck. My understanding is I need to do the following:

1.) Create a new file at the src level of the app. I have done that, and have a file titled "custom_theme.scss" that looks like this:

@import '~@angular/material/core/theming/all-theme';
 @import 'sass-material-colors-classes';
 @include md-core();
 
 // Customizations go here, for instance:
 $app-primary: md-palette($md-indigo);
 $app-accent:  md-palette($md-green, 500);
 $app-warn:    md-palette($md-red);
 
 // Create the theme object (a Sass map containing all of the palettes).
 $app-theme: md-light-theme($app-primary, $app-accent, $app-warn);
 
 @include angular-material-theme($app-theme);

2.) I am then including that as an import in my src level "styles.css" file, like this:

    @import '~@angular/material/core/theming/prebuilt/deeppurple-amber.css';
    @import 'custom_theme.scss';

When I then try and boot up the app, I get a compilation error:

ERROR in .//css-loader?{"sourceMap":false}!./src/custom_theme.scss
Module not found: Error: Can't resolve
'@angular/material/core/theming/all-theme' in
'/Users/dg/Documents/abc/kra/abc/src' @
./
/css-loader?{"sourceMap":false}!./src/custom_theme.scss 3:10-123 @
.//css-loader?{"sourceMap":false}!.//postcss-loader!./src/styles.css
@ ./src/styles.css @ multi ./src/styles.css

Not sure what's going on here. Some additional info, I'm actually using LESS in this app. But according to the official docs, this shouldn't be a problem - as it states that one doesn't need to be using scss throughout the app, it's just this one file that needs to be scss. And, because this is an Angular-CLI project, it should compile automatically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs: investigationRequires some digging to determine if action is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions