Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(theming): 'Could not find Angular Material core theme' warning with new Angular 18 application using Angular Material #29115

Closed
1 task
hunterbring opened this issue May 24, 2024 · 7 comments · Fixed by #29118
Assignees
Labels
area: material/core P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@hunterbring
Copy link

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

When generating a new application and adding @angular/material with a custom theme, the following warning message is shown in the console:

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

However, the core mixin is present in the styles.scss file:

// Custom Theming for Angular Material
// For more information: https://material.angular.io/guide/theming
@use '@angular/material' as mat;

// Plus imports for other components in your app.
// Include the common styles for Angular Material. We include this here so that you only
// have to load a single css file for Angular Material in your app.
// Be sure that you only ever include this mixin once!
@include mat.core();

// Define the theme object.
$test-theme: mat.define-theme((
  color: (
    theme-type: light,
    primary: mat.$azure-palette,
    tertiary: mat.$blue-palette,
  ),
  density: (
    scale: 0,
  )
));

// 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.
:root {
  @include mat.all-component-themes($test-theme);
}

// Comment out the line below if you want to use the pre-defined typography utility classes.
// For more information: https://material.angular.io/guide/typography#using-typography-styles-in-your-application.
// @include mat.typography-hierarchy($test-theme);

// Comment out the line below if you want to use the deprecated `color` inputs.
// @include mat.color-variants-backwards-compatibility($test-theme);

/* You can add global styles to this file, and also import other style files */
html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Roboto, "Helvetica Neue", sans-serif;
}

Attempting to include the core theme explicitly using @include mat.core-theme($test-theme) also has no effect.

Reproduction

StackBlitz link: N/A (StackBlitz failed to run newly generated Angular 18 application)

Steps to reproduce:

  1. Generate a new application using ng new test-app
    • Do you want to enable Server-Side Rendering (SSR) and Static Site Generation (SSG/rerendering)?
      • No
  2. Add Angular Material to the project using ng add @angular/material
    • Theme type
      • Custom
    • Set up global Angular Material typography styles?
      • Yes
    • Include the Angular animations module?
      • Include and enable animations
  3. Replace the content of app.component.html with the following:
    <button mat-flat-button>
      Test
    </button>
    
  4. Add an import for the MatButtonModule to the imports array in app.component.ts
  5. Serve the application
  6. Open the Developer Tools
  7. View the console

Expected Behavior

No warning should be present.

Actual Behavior

The following warning is shown in the console:

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

The button added in the app.component.html renders as expected.

Environment

$ ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 18.0.1
Node: 20.13.1
Package Manager: npm 10.5.2
OS: win32 x64

Angular: 18.0.0
... animations, cdk, common, compiler, compiler-cli, core, forms
... material, platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1800.1
@angular-devkit/build-angular   18.0.1
@angular-devkit/core            18.0.1
@angular-devkit/schematics      18.0.1
@angular/cli                    18.0.1
@schematics/angular             18.0.1
rxjs                            7.8.1
typescript                      5.4.5
zone.js                         0.14.6
@hunterbring hunterbring added the needs triage This issue needs to be triaged by the team label May 24, 2024
@crisbeto crisbeto self-assigned this May 24, 2024
@crisbeto crisbeto added area: material/core P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed needs triage This issue needs to be triaged by the team labels May 24, 2024
crisbeto added a commit to crisbeto/material2 that referenced this issue May 25, 2024
Fixes that all M3 themes were causing a "no theme has been loaded" warning to be logged, because they weren't inserting the loaded marker.

Note: it's tempting to create the marker as a token, but we can't do it because tokens are output under a selector, whereas we want the marker to always be at the top level since we detect it by creating an element and inserting it into the `body`.

Fixes angular#29115.
crisbeto added a commit to crisbeto/material2 that referenced this issue May 25, 2024
Fixes that all M3 themes were causing a "no theme has been loaded" warning to be logged, because they weren't inserting the loaded marker.

Note: it's tempting to create the marker as a token, but we can't do it because tokens are output under a selector, whereas we want the marker to always be at the top level since we detect it by creating an element and inserting it into the `body`.

Fixes angular#29115.
crisbeto added a commit to crisbeto/material2 that referenced this issue May 25, 2024
Fixes that all M3 themes were causing a "no theme has been loaded" warning to be logged, because they weren't inserting the loaded marker.

Note: it's tempting to create the marker as a token, but we can't do it because tokens are output under a selector, whereas we want the marker to always be at the top level since we detect it by creating an element and inserting it into the `body`.

Fixes angular#29115.
@ivorobioff
Copy link

I can confirm that I see the same warnings in the same environment

@crisbeto
Copy link
Member

It'll be fixed by #29118.

crisbeto added a commit that referenced this issue May 28, 2024
Fixes that all M3 themes were causing a "no theme has been loaded" warning to be logged, because they weren't inserting the loaded marker.

Note: it's tempting to create the marker as a token, but we can't do it because tokens are output under a selector, whereas we want the marker to always be at the top level since we detect it by creating an element and inserting it into the `body`.

Fixes #29115.
crisbeto added a commit that referenced this issue May 28, 2024
Fixes that all M3 themes were causing a "no theme has been loaded" warning to be logged, because they weren't inserting the loaded marker.

Note: it's tempting to create the marker as a token, but we can't do it because tokens are output under a selector, whereas we want the marker to always be at the top level since we detect it by creating an element and inserting it into the `body`.

Fixes #29115.

(cherry picked from commit 233c8a3)
@Raghu0701
Copy link

Hi @crisbeto I am using Angular 18.0.1 I tried the above steps but still I see the warning appearing in devtools. Can you please help solving this. PFB the codebase for the same

https://github.com/Raghu0701/angular-material-18-test

@crisbeto
Copy link
Member

@Raghu0701 it looks like that project is on 18.0.0. You should update the package.json to be ^18.0.1 instead.

@Raghu0701
Copy link

Raghu0701 commented May 30, 2024

@crisbeto Thanks for your reply. I tried updating the packages using ng update command but still I see the in devtools. Additionally when I tried assigning primary color to navbar it has no effect on browser.

have updated the code in the github repository

Am I missing anything here ? please help as I am new to angular 18

@comanescuadrian95
Copy link

comanescuadrian95 commented Jun 19, 2024

@crisbeto I updated the angular material to the latest angular 18.0.2. Warning is still present.

image

image
image
image
image

@crisbeto
Copy link
Member

crisbeto commented Jun 19, 2024

@comanescuadrian95 can you check in your node_modules if it's actually 18.0.2? Also how are you including your theme?

For what it's worth, you can also disable the warning by providing this:

{
  provide: MATERIAL_SANITY_CHECKS,
  useValue: false
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/core P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants