angular: StaticInjectorError(Platform: core)[RouterScroller -> ViewportScroller]

Hi,

I am getting below error after updating the angular(ionic) application.

core.js:7376 ERROR NullInjectorError: StaticInjectorError(AppModule)[RouterScroller -> ViewportScroller]: StaticInjectorError(Platform: core)[RouterScroller -> ViewportScroller]: NullInjectorError: No provider for ViewportScroller! at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (http://localhost:8100/vendor.js:62254:25) at resolveToken (http://localhost:8100/vendor.js:63623:24) at tryResolveToken (http://localhost:8100/vendor.js:63567:16) at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (http://localhost:8100/vendor.js:63471:20) at resolveToken (http://localhost:8100/vendor.js:63623:24) at tryResolveToken (http://localhost:8100/vendor.js:63567:16) at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (http://localhost:8100/vendor.js:63471:20) at resolveNgModuleDep (http://localhost:8100/vendor.js:82413:29) at _callFactory (http://localhost:8100/vendor.js:82481:67) at _createProviderInstance (http://localhost:8100/vendor.js:82433:26)

Part of the package.json file is

@angular/animations”: “^8.1.0”, “@angular/common”: “^8.1.0”, “@angular/core”: “^8.1.0”, “@angular/forms”: “^8.1.0”, “@angular/http”: “^7.2.15”, “@angular/platform-browser”: “^8.1.0”, “@angular/platform-browser-dynamic”: “^8.1.0”, “@angular/router”: “^8.1.0”, “@ionic-native/core”: “^5.9.0”, “@ionic/angular”: “^4.6.0”

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 13
  • Comments: 35 (10 by maintainers)

Most upvoted comments

I am going to close this, because there is not sufficient information for us to understand and reproduce the problem. (Please check out our submission guidelines to understand why we can’t act on issues that are lacking important information.)

As mentioned in https://github.com/angular/angular/issues/31425#issuecomment-508773544, my best guess is that it is not a problem in Angular itself (but, again, we can’t be sure).

If the problem still exists in your application, please open a new issue and follow the instructions in the issue template.

Same issue here after install @angular/cdk

I get the same error after yarn upgrade @angular/cli @angular/core

I added the following in app.component.ts:

constructor(private ViewportScroller: ViewportScroller){ this.viewportscroller; }

The error is gone, but probably not the best fix. I can’t figure out how the error is triggered, when I’m not using the ViewportScroller.

Thx for the following up, @chantimothy. Maybe ng upgrade was confused by the fact that some packages were on different versions than others. Normally that would never happen.

Glad you were able to sort it out anyway.

To everyone getting this error: Make sure you Angular packages are on the same version 😃

@mlc-mlapis I am not using ViewportScroller anywhere in my application. Just wondering why I am getting this error. If ViewportScroller is part of any other dependency, it should be present in the package by itself. Correct me if I am going wrong.

I did ng update --all --force and it fixed the issue. In case you get issue with respect to Typescript version, please decrease the version and run npm i.

Just make sure that whatever version of angular cli u are using should be same for angular core, material and the other dependencies. If the version differs then there is a problem with the dependencies.

Thanks @gkalpak , it worked 😃

I get the same error after yarn upgrade @angular/cli @angular/core

same issue

image

@gkalpak … ah, sure. You were right, of course. I was too fast.

same problem here. seems like every release brings more breaking changes. ng update --all --force worked for me but only after then editing package.json and setting typescript back to "typescript": "~3.4.0" then running npm install apparently something in update thought I needed "typescript": "~3.63" but that broke something as well.

@dcolakchile Today i faced same error. I tried “ng update @angular/cli @angular/core” . It automatically updated required angular packages and error disappeared. You can also refer https://stackoverflow.com/questions/56879099/nullinjectorerror-no-provider-for-viewportscroller

image

this error when i am using ngx-mat-file-input concept please tell the solutions

same issue, after adding @angular/material to my project,

  1. i got error that @angular/animation not same version as @angular/core, so i updated (I’m using NPM).
  2. I’m getting this error.