19

I followed each steps described here: https://material.angular.io/guide/getting-started

Error I get

ERROR in ./src/app/app.module.ts
Module not found: Error: Can't resolve '@angular/material' in '/Users/isabelle/my-project/src/app'
@ ./src/app/app.module.ts 14:0-51
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

What I did

npm install -g @angular/cli
ng new my-project
npm install --save @angular/material

In src/app/app.module.ts

import { MaterialModule } from '@angular/material';
    
    // other imports 
@NgModule({
    imports: [MaterialModule],
    ...
})   
export class PizzaPartyAppModule { }

10 Answers 10

24

I did that command again and everything ran smoothly

npm install --save @angular/material
Sign up to request clarification or add additional context in comments.

3 Comments

This now gives me: Module not found: Error: Can't resolve '@angular/cdk/a11y'
As per updated Angular Material documentation, the ng add @angular/material command will install Angular Material, Component Dev Kit (CDK) and Angular Animations. Thus, it is a combination of various npm install commands for all of them separately.
@M M, Angular needs to update their docs pronto. Running the command ng add @angular/material won't install all those things which you said. Rather a run of these commands: npm i @angular/material --save and npm i @angular/cdk --save will definitely install ALL those pkgs. I have been there and i am currently have Angular v12.0.2 and Angular Material 12 running on my pc.
19
npm install --save @angular/material

npm install --save @angular/cdk

restart dev server

(usually the console will tell you when there are dependencies, pay attention to it)

Comments

3

Simply add it to your project

ng add @angular/material

Comments

2

Delete node_modules and run npm install.

Comments

1

first try only this command

  1. npm install --save @angular/material

OR if not work then

  1. npm install --save @angular/material
  2. npm install --save @angular/cdk

Comments

1

install angular material

npm install @angular/material

check and edit yuor imports component... for example:

import {MatTableDataSource} from '@angular/material/table';

Comments

0

Try installing latest version of rxjs using following commands npm install rxjs @latest

1 Comment

How does this solve the problem better that the accepted answer?
0

after running this command

ng add @angular/material

I get error

Error: Can't resolve '@angular/cdk/a11y'

then I restart my application and all OK

Comments

0

I had this same issue, I was building the project from the scratch. For me what I did wrong is I was trying to run

ng add @angular/material

Before running the

npm install

Command

Once I ran the "npm install" first and then tried to install materials, everything started to install properly without any issues. Its a very silly basic mistake which is worth to note for beginers like me :)

Comments

0

Delete Your node_modules folder and package.lock.json file manually and then npm install if not work then ng add@angular/material

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.