37

I am getting this error when i tried to use MatToolBar in my angular app. In browser I get Uncaught TypeError: Object(...) is not a function and also get warnings in the console:

WARNING in ./node_modules/@angular/cdk/esm5/text-field.es5.js 146:151-159
"export 'ɵɵinject' was not found in '@angular/core'

WARNING in ./node_modules/@angular/cdk/esm5/a11y.es5.js 2324:206-214
"export 'ɵɵinject' was not found in '@angular/core'

How can I resolve this? On github it is a closed issue.

  • Please add a code snippet with the content of your package.json file. – tottomotto Jun 03 '19 at 20:04
  • What version of angular core are you using? [Is it 8 by any chance?](https://github.com/angular/angular/issues/30413) – msanford Jun 03 '19 at 20:07
  • Possible duplicate of [Angular Compilation Warnings with Angular Material Declarations](https://stackoverflow.com/questions/56417164/angular-compilation-warnings-with-angular-material-declarations) – msanford Jun 03 '19 at 20:07
  • I've seen these kinds of errors when Ivy is enabled. If you have it on try turning it off. – Reactgular Jun 03 '19 at 21:14
  • I try make it https://stackoverflow.com/questions/56417164/angular-compilation-warnings-with-angular-material-declarations but i can't solved – Mr Ralph Jun 04 '19 at 14:08
  • This one was a toughy for me too. Was trying to use Angular 7 with firebase. I was getting those errors alike when using ng serve. I dough a bit more and it looked like my @angular/core version was wrong...so thats my thought on where the issue was. I just upgraded to angiular 9.0.0 and everything is working now – tony2tones Apr 25 '20 at 18:50

10 Answers10

20

So apparently after wasting 1 hour on the same issue, it seems your angular version and the material version should be same i.e if your angular CLI version is 7, you should use material version 7.

Just change the dependencies "@angular/material" and "@angular/cdk" version to "7.3.7" and change "@angular/animations" to "7.2.15"

Hope this solves your problem.

Aayush
  • 409
  • 4
  • 17
  • I did this but now get: Error: StaticInjectorError(AppModule)[ScullyLibModule -> IdleMonitorService]: StaticInjectorError(Platform: core)[ScullyLibModule -> IdleMonitorService]: NullInjectorError: No provider for IdleMonitorService! – Evan Aug 04 '20 at 00:21
  • @Evan, it looks like you forgot to import the `IdleMonitorService` in your provider settings in your `AppModule` – Craig Wayne Jan 25 '21 at 09:38
  • This helped me with ngx-filesaver – BrunoElo Oct 29 '21 at 12:27
  • This has solved it for me! Thanks! – MichaelEr Jul 14 '23 at 21:40
14

The solution is to ensure all your packages are of the same versions.

Check Package.json file to find if the packages are on the same version.

Then in the command line use the command

ng update @angular/core

This should solve the problem

nXn
  • 904
  • 6
  • 13
5

I have resolved it, I just updated the dependency of angular material to 7 and angular version to 7.3.2 and it worked.

4

This worked for me:

ng update @angular/core
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
3

I have resolved it, we need to install proper npm plugin version corresponding to angular version.

For instance, if you are installing ngx-toastr then run; npm i ngx-toastr@10.1.0 for angular 8.x, 7.x, 6.x.

Check the support link for ngx-toastr version support for angular, which can be found here.

RobC
  • 22,977
  • 20
  • 73
  • 80
sandeep
  • 76
  • 5
1

At first, I used below commands

npm install -S @angular/cdk @angular/animations
npm uninstall @angular/core
npm install -S @angular/core

Now, this solved this issue but then I faced this error

NullInjectorError: No provider for ViewportScroller

Solved that error by using the below command

ng update @angular/cli @angular/core
HV Sharma
  • 4,891
  • 3
  • 15
  • 30
1

WARNING in

./node_modules/@ng-select/ng-select/fesm2015/ng-select-ng-select.js

2560:52-70 "export 'ɵɵdefineInjectable' was not found in '@angular/core'

Just removed the ɵɵ from ɵɵdefineInjectable in the 3 occurrences in ./node_modules/@ng-select/ng-select/fesm2015/ng-select-ng-select.js

and it's working properly, thanks.

Arséne
  • 95
  • 4
0

Just resolved this issue with Angular primeng. Just make sure @angular/cdk version and primeng version are same. It will work.

Also, make sure of there same versions as well. "@angular/cdk": "^7.3.7", "@angular/material": "^7.3.7",

Taimoor Tahir
  • 430
  • 4
  • 6
0

I used @angular/core 7.x.x and I found a similar problem after I have installed npm install ngx-toastr --save. The ngx-toastr was version 11.x.x but the @angular/core was version 7.x.x

I have fixed it by updating the @angular/core and it updated to version 8.2.10

ng update @angular/core
KHACHORNCHIT
  • 2,222
  • 23
  • 19
0

I had an issue in my App.component.ts test as I hadn't declared providers in the test for all my providers in the constructor. The issue landed me the "no tests founds" issue.

Bjerh
  • 71
  • 5