Nick Buzzy
Nick Buzzy

Reputation: 115

Error Adding Angular Material to Existing Angular 7 App

I am attempting to add Angular Material to my existing Angular 7 app so that I can use the MatDialogModule. I keep getting the following error:

WARNING in ./node_modules/@angular/cdk/esm5/a11y.es5.js 2324:55-73 export 'ɵɵdefineInjectable' was not found in '@angular/core'

Below are the relevant portions of my app.module.ts and package.json

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import { MatDialogModule } from '@angular/material/dialog';

 ...

@NgModule({

  imports: [
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
    AppRoutingModule,
    [BrowserAnimationsModule],
    MatDialogModule,
  ],

```json

  "dependencies": {
    "@angular/animations": "^7.2.15",
    "@angular/cdk": "^8.0.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/material": "^8.0.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "core-js": "^2.5.4",
    "hammerjs": "^2.0.8",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.5",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2"
  }

Upvotes: 1

Views: 2308

Answers (5)

Santosh Kadam
Santosh Kadam

Reputation: 1352

"@angular/cdk": "^8.0.0", should be changed to you angular version. By default it install latest version.

Upvotes: 0

Mateo Tibaquira
Mateo Tibaquira

Reputation: 2136

If you're upgrading your site, be sure to update all your dependencies via ng update, and if your problem remains, you may need to remove your node_modules folder and reinstall them with npm install to be sure that there are no problems with them.
Happy coding!

Upvotes: 0

Ultan Kearns
Ultan Kearns

Reputation: 115

I had the exact same problem when you run

npm install

you should see some warnings saying you need to install another package for angular material to work. In my case I had to run

npm i @angular/core@^8.0.0

Hope this helps.

Upvotes: 1

Adam
Adam

Reputation: 21

I had this same issue, and it was that i was using @angular/[email protected] and @angular/[email protected] and @angular/[email protected].

I know you mentioned downgrading material and cdk, but maybe your core version was mismatched. by making sure all 3 were ~7.2.0, and properly importing material after the browsermodule, i was able to get the app to run.

Upvotes: 2

Dev Gourav
Dev Gourav

Reputation: 136

Delete your ./nodule_modules folder and run

 npm init

Upvotes: -1

Related Questions