You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug(*): Issue with ng add @angular/material in Angular CLI #28985
Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
17.3.5
Description
Dear Angular Team,
I encountered an issue while using the Angular CLI to integrate @angular/material into a new project. Here are the steps I followed and the problem I observed:
Environment:
Angular project created using the Angular CLI.
Angular CLI version: [18.2.12].
Node.js version: [22.11.0].
Issue:
I ran the command ng add @angular/material in the terminal.
The installation was marked as successful, but the necessary project files (e.g., angular.json, app.config.ts, styles.css, etc) were not modified.
Run npx @angular/cli@18 new ng18-app --no-standalone --no-ssr --style=scss
Navigate to the directory: cd ng18-app
Run ng add @angular/material
Command output:
➜ ng18-app git:(master) ng add @angular/material
✔ Determining Package Manager
› Using package manager: npm
✔ Searching for compatible package version
› Found compatible package version: @angular/[email protected].
✔ Loading package information from registry
✔ Confirming installation
✔ Installing package
? Choose a prebuilt theme name, or "custom" for a custom theme: Indigo/Pink [ Preview: https://material.angular.io?theme=indigo-pink ]
? Set up global Angular Material typography styles? yes
? Include the Angular animations module? Include and enable animations
UPDATE package.json (1108 bytes)
✔ Packages installed successfully.
Cannot find module '/ng18-app/node_modules/@schematics/angular/private/components.js'
Strangely, Angular v17.0.0 is chosen as the compatible version which seems wrong.
In a freshly generated Angular 19 app, everything seems to work just fine.
@alan-agius4 I think you misunderstood the issue. When creating a fresh Angular 18 non-standalone workspace without Material, after running ng add @angular/material the wrong version of Angular Material is chosen, which probably leads to the described issue. Just try out the reproduction steps I added.
this was not fixed. I have the issue today. I force cleared my NPM cache, and create a fresh angular 18.2.12 app, ng add @angular/material, and it chose material v17 again. "found compatible package version: @angular/[email protected]"
While resolving: [email protected]
Found: @angular/[email protected]
node_modules/@angular/core
@angular/core@"^18.2.0" from the root project
peer @angular/core@"^18.0.0 || ^19.0.0" from @angular/[email protected]
node_modules/@angular/material
@angular/material@"18.2.14" from the root project
Could not resolve dependency:
peer @angular/core@"19.0.1" from @angular/[email protected]
node_modules/@angular/animations
peer @angular/animations@"^18.0.0 || ^19.0.0" from @angular/[email protected]
node_modules/@angular/material
@angular/material@"18.2.14" from the root project
Fix the upstream dependency conflict, or retry
this command with --force or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.
No one angular material version is working for me in Angular Project cli18
Without updating anything other than package.json.
I just removed the @angular/material and @angular/cdk dependencies from the package.json and made a new installation declaring the desired version:
ng add @angular/material@18
I tested it and it worked perfectly!
Reacted by laiminaRida, Alexandre Oliveira Curvelo, AbhijeetChandra, marcflausino, Raúl Camacho., Arif Nawas, DoblamosSA, AY, Víctor Izquierdo, Pablo Marzal and 4 more
As said above, I removed @angular/material and @angular/cdk dependencies from the package.json and made a new installation declaring the desired version,
Activity
json-derulo commentedon Nov 27, 2024
To reproduce:
npx @angular/cli@18 new ng18-app --no-standalone --no-ssr --style=scsscd ng18-appng add @angular/materialCommand output:
Strangely, Angular v17.0.0 is chosen as the compatible version which seems wrong.
In a freshly generated Angular 19 app, everything seems to work just fine.
Versions:
crisbeto commentedon Nov 27, 2024
This is likely an issue either with the setup or with the CLI. Transferring to the correct repo.
alan-agius4 commentedon Nov 27, 2024
The problem appears that you have an outdated version of
@angular/materialinstalled.json-derulo commentedon Nov 27, 2024
@alan-agius4 I think you misunderstood the issue. When creating a fresh Angular 18 non-standalone workspace without Material, after running
ng add @angular/materialthe wrong version of Angular Material is chosen, which probably leads to the described issue. Just try out the reproduction steps I added.alan-agius4 commentedon Nov 27, 2024
Sorry I misunderstood the issue. As a workaround you can provide the version specifier. Example:
ng add @angular/material@18fix(@angular/cli): correctly sort package versions in ascending order…
fix(@angular/cli): correctly select package versions in descending or…
fix(@angular/cli): correctly select package versions in descending or…
fix(@angular/cli): correctly select package versions in descending or…
deerbuster commentedon Nov 28, 2024
this was not fixed. I have the issue today. I force cleared my NPM cache, and create a fresh angular 18.2.12 app, ng add @angular/material, and it chose material v17 again. "found compatible package version: @angular/[email protected]"
JeanMeche commentedon Nov 28, 2024
@deerbuster The fixed was merged (for v19) but wasn't released yet. Also you have a workaround mentionned in Alan last message.
AngeloCinaWD commentedon Dec 3, 2024
Angular project 18.2.13
ng add @angular/material@18
Not working
npm resolution error report
While resolving: [email protected]
Found: @angular/[email protected]
node_modules/@angular/core
@angular/core@"^18.2.0" from the root project
peer @angular/core@"^18.0.0 || ^19.0.0" from @angular/[email protected]
node_modules/@angular/material
@angular/material@"18.2.14" from the root project
Could not resolve dependency:
peer @angular/core@"19.0.1" from @angular/[email protected]
node_modules/@angular/animations
peer @angular/animations@"^18.0.0 || ^19.0.0" from @angular/[email protected]
node_modules/@angular/material
@angular/material@"18.2.14" from the root project
Fix the upstream dependency conflict, or retry
this command with --force or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.
No one angular material version is working for me in Angular Project cli18
YasminHernandes commentedon Dec 4, 2024
Hi guys, I had the same problem with a new Angular 18 project. I installed Angular Material using:
and it gave me the same error message:
Without updating anything other than package.json.
I just removed the
@angular/materialand@angular/cdkdependencies from thepackage.jsonand made a new installation declaring the desired version:I tested it and it worked perfectly!
Hi-AY commentedon Dec 30, 2024
Hello, I was getting this same issue.
As said above, I removed
@angular/materialand@angular/cdkdependencies from thepackage.jsonand made a new installation declaring the desired version,Now I am getting this,
Cannot read properties of null (reading 'endTag')Any idea about this?
YasminHernandes commentedon Jan 3, 2025
Check your code for duplicate or missing end tags.
https://stackoverflow.com/questions/62203754/ng-add-angular-material-fails-with-cannot-read-property-endtag-of-null
Hi-AY commentedon Jan 7, 2025
It was resolved. Thank you @YasminHernandes !!
fix(@angular/cli): correctly select package versions in descending or…
fix(@angular/cli): correctly select package versions in descending or…
angular-automatic-lock-bot commentedon Feb 7, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.