components: Could not find Angular Material core theme. Most Material components may not work as expected. For more info refer to the theming guide: https://material.angular.io/guide/theming
Hi! Ciao! How Are You???
Bug, feature request, or proposal:
Could not find Angular Material core theme, although all core @include mat-core();
is included. I got 6 themes, all working except the warning.
What is the expected behavior?
No warning.
What is the current behavior?
Warning.
What are the steps to reproduce?
git clone https://github.com/patrikx3/corifeus-app-web-pages.git
cd corifeus-app-web-pages
yarn install
grunt run
See.
What is the use-case or motivation for changing an existing behavior?
Themes.
Which versions of Angular, Material, OS, browsers are affected?
Current.
Is there anything else we should know?
Nope.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 36 (10 by maintainers)
Commits related to this issue
- fix: delay on-load sanity checks Delays the sanity checks from the `CompatibilityModule` by 5 seconds, in order to give the user's base styles a better chance to load. Fixes #4125. — committed to crisbeto/material2 by crisbeto 7 years ago
- fix: delay on-load sanity checks Delays the sanity checks from the `CompatibilityModule` by 5 seconds, in order to give the user's base styles a better chance to load. Fixes #4125. — committed to crisbeto/material2 by crisbeto 7 years ago
- fix: delay on-load sanity checks Delays the sanity checks from the `CompatibilityModule` by 5 seconds, in order to give the user's base styles a better chance to load. Fixes #4125. — committed to crisbeto/material2 by crisbeto 7 years ago
- fix: allow users to disable the sanity checks Allows users to disable the Material sanity checks, by providing a value for the `MATERIAL_SANITY_CHECKS` token: ```ts @NgModule({ providers: [ {p... — committed to crisbeto/material2 by crisbeto 7 years ago
- fix: allow users to disable the sanity checks (#4178) Allows users to disable the Material sanity checks, by providing a value for the `MATERIAL_SANITY_CHECKS` token: ```ts @NgModule({ provide... — committed to angular/components by crisbeto 7 years ago
This issue tied me in knots, but eventually, I realised that what Angular’s own Materials tutorial doesn’t tell us is that we must include this line in the “styles.css” file, to make the controls appear normally (certainly in Windows 7).
@import “…/node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css”;
Trying to include that file using an “include”, even in the index.html file, failed miserably for me. It could never locate this .css file… even if I manually copied it into the same folder as index.html.
@sharpevo thanks a lot for your help. I had the issue when running tests using karma. Your fix does not work for this use case, however adding the theme file in karma.conf.js as follows fixes the issue
Okay, my mistake was the following:
@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';
I put this line in
src/app/app.component.css
instead ofsrc/styles.css
.It seems like the warning itself could be removed in favor of a clearer set of requirements in the documentation.
I may be missing some other reason for its existence, but it appears that the compatibility module is just checking to make sure you’ve put
@include mat-core();
in your style. Couldn’t that requirement be made more obvious (e.g., bold) in the docs, rendering the warning redundant?Personally, the idea of tweaking timers to do css checks feels a bit hacky.
That warning is a sanity check that won’t be done in production mode. If you want to disable it in development mode, you can use the
MATERIAL_SANITY_CHECKS
token:@crisbeto GREAT! Your documentation does describe each directive such as
mat-core
andangular-material-theme
. I GET THAT!!Now, where do I refer to theme.scss so that it is compiled and included in the page before receiving the error
Could not find Angular Material core theme.
?Let me explain what we need answered in this thread. Lets say I have some basic css and the material theme color instructions all contained in
theme.scss
. Follow me so far? Do I put theme.scss in tsconfig? E.g.:NOPE! That’s not going to work!
Where do I put theme.scss so that it is compiled? Maybe angular-cli.json?
NO, that doesn’t work because it doesn’t compile scss, it just inserts css into the head of index.html. Error:
Could not find Angular Material core theme
In my app.component.ts? https://github.com/ng-seed/universal/blob/master/src/client/app/app.component.ts
NO! That only works with awesome-typescript-loader and webpack, doesn’t work with angular-cli?
How about using
encapsulation: ViewEncapsulation.None
in app.component.ts?HEY THAT WORKS! Except we still get this error message even though everything looks correct.
Any ideas? Anyone? Does every theme have to start with a precompiled color in order to resolve this error? Do you start with a precompiled theme and then override the theme meaning it injects multiple themes in to your page?
What is the most up to date method for doing this and why isn’t it made clear on this page? https://material.angular.io/guide/theming
@willshowell Provides a great example of a use case with linking multiple
.scss
files together: https://github.com/angular/material2/issues/6063#issuecomment-318141302Just to mention the file to edit where styles.css is configured is .angular-cli.json, not angular-cli.json. A hidden file on Unix OSes.
In src/styles.css, either this :
@import "../node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css";
or this:
@import "~@angular/material/prebuilt-themes/deeppurple-amber.css";
worked for me on @angular/cdk 5.0.0-rc0.
It seems that none of the above solutions works for me. After tons of tests with
rm -rf node_modules
andnpm install
, the result is really weird.Finally, the config is:
and the dependencies in package.json are:
Ahh, if you have some something weird with Electron and Angular Material, make sure if you use ipcRenderer from Electron, make sure use it in the NgZone.run!!! Now it is fine, perfect. 1 month sadness!!!
Thanks guys so much!
For newcomers, @siebmanb’s solution also worked for me. Note that the absolute path should be used (e.g.
node_modules/@angular/material/...
instead of../../node_modules/@angular/material/...
). Thanks @siebmanb !!We do have info about it in the docs @Torqode, however people tend to miss it, which ends up looking like it works in some cases, but breaks once you start using the overlay-based components. I’m not sure that making it bolder will solve the issue.