39

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.

6

10 Answers 10

21

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.

4
  • I did this but now get: Error: StaticInjectorError(AppModule)[ScullyLibModule -> IdleMonitorService]: StaticInjectorError(Platform: core)[ScullyLibModule -> IdleMonitorService]: NullInjectorError: No provider for IdleMonitorService!
    – Evan
    Commented Aug 4, 2020 at 0:21
  • @Evan, it looks like you forgot to import the IdleMonitorService in your provider settings in your AppModule Commented Jan 25, 2021 at 9:38
  • This helped me with ngx-filesaver
    – Emeka Elo
    Commented Oct 29, 2021 at 12:27
  • This has solved it for me! Thanks!
    – MichaelEr
    Commented Jul 14, 2023 at 21:40
17

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

4
  • 5
    For anyone else reading this, the above command will also update other parts of Angular.
    – Pytth
    Commented Jan 15, 2020 at 23:07
  • 3
    this is lightly considered advice
    – Omar
    Commented Feb 13, 2020 at 19:30
  • 4
    This command will also try to update the angular version, which might be not what everyone was looking for. Commented Aug 14, 2020 at 13:09
  • The above command will update to latest angular, if you wanna update to a specific version you can add version at the last for ex: ng update @angular/[email protected] Commented May 17, 2022 at 5:39
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.

5

This worked for me:

ng update @angular/core
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 [email protected] for angular 8.x, 7.x, 6.x.

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

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
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.

2
  • 8
    I don't think removing code in "node_modules" folder is a good answer....
    – Cocorico
    Commented Sep 2, 2021 at 8:42
  • wtf!! awesome Answer ! and stupid ! Working for me XDDDDDD Commented Aug 29, 2022 at 20:02
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",

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
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.