Ng-zorro-antd: StaticInjectorError(AppModule)[CdkConnectedOverlay -> Overlay]

Created on 3 Jul 2019  路  7Comments  路  Source: NG-ZORRO/ng-zorro-antd

Reproduction link

https://stackblitz.com/edit/ng-zorro-antd-start-hspl9z?file=package.json

Steps to reproduce

Build works perfectly when doing a normal ng serve. Doing a --prod build compiles correctly. However browsing to the site in a browser that has been built in --prod mode, does not work.

I see that ng-zorro has a dependency on @angular/cdk. I also need to use the cdk dep in my own project so I need to add a reference to the project. As 7.5.1 uses cdk 7.3.7 as a dependency (from lock file), I added this version to my project.

I do not know what could be causing this.

What is expected?

Running an angular site in --prod mode should work correctly. Currently I have a site that does not work properly now.

What is actually happening?

In the browser, there are many errors like this:

ERROR Error: StaticInjectorError[t -> t]: 
  StaticInjectorError(Platform: core)[t -> t]: 
    NullInjectorError: No provider for t!

If you disable the terser step of a --prod build the error looks as follows:

main.69af81de163627084b5e.js:28873 ERROR Error: StaticInjectorError(AppModule)[CdkConnectedOverlay -> Overlay]:
 StaticInjectorError(Platform: core)[CdkConnectedOverlay -> Overlay]:
   NullInjectorError: No provider for Overlay!

| Environment | Info |
|---|---|
| ng-zorro-antd | 7.5.1 |
| Browser | Chrome |


Note I cannot update to angular 8 and the latest version of ng-zorro just yet.

My packages file:

"dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/cdk": "7.3.7",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "@auth0/angular-jwt": "^2.1.0",
    "@swimlane/ngx-charts": "^12.0.1",
    "angular-datatables": "^8.0.0",
    "angularx-qrcode": "^1.6.0",
    "bootstrap": "^4.3.1",
    "chart.js": "^2.8.0",
    "color-hash": "^1.0.3",
    "core-js": "^2.5.4",
    "datatable-sorting-datetime-moment": "^1.0.1",
    "datatables.net": "^1.10.19",
    "datatables.net-bs4": "^1.10.19",
    "datatables.net-buttons": "^1.5.6",
    "datatables.net-buttons-bs4": "^1.5.6",
    "datatables.net-responsive": "^2.2.3",
    "datatables.net-responsive-bs4": "^2.2.3",
    "file-saver": "^2.0.2",
    "jquery": "^3.4.1",
    "moment": "^2.24.0",
    "ng-zorro-antd": "^7.5.1",
    "ng2-charts": "2.2.5",
    "ngx-color-picker": "^8.0.1",
    "ngx-page-scroll-core": "^6.0.2",
    "ngx-summernote": "^0.6.5",
    "rxjs": "~6.3.3",
    "summernote": "^0.8.12",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.9",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/datatables.net": "^1.10.17",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/jquery": "^3.3.29",
    "@types/node": "^8.9.5",
    "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",
    "webpack-bundle-analyzer": "3.3.2"
  }

All 7 comments

Fixed. In app.module.ts these modules need to be included:
ScrollingModule, DragDropModule

@dylanvdmerwe Doesn't work for me. Does it work for you in angular 8.1.1 and ng-zorro-antd 8.1.0?

I have not tried NG 8 yet. Probably some other module required?

Adding CdkConnectedOverlay to providers list of each module you use may fix this problem. It works for me.
image

@amiram is right! I had the same problem. I have angularCDK in package.json and ngZorro is having another version as a dependency and this causes issues always

For anyone who's still stuck with these: I spent ~6 hours behind this. Got it working via some hacky methods (removing/replacing zorro's dependency version, matching my project's CDK with zorro's ... )
Finally, upgrading angular + cdk + zorro to the latest (8.x/9.x) seemed to be the best solution. The time invested in this migration was very well worth it on multiple levels. Zero hacks, zero errors now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vthinkxie picture vthinkxie  路  3Comments

s01c83l picture s01c83l  路  3Comments

IsaacHub picture IsaacHub  路  3Comments

IonelLupu picture IonelLupu  路  3Comments

linjianhong picture linjianhong  路  3Comments