39
votes

I am encountering the error: "Module not found: Error: Can't resolve '@angular/cdk/scrolling'" as soon as I add import TableModule from primeNG in app.module.ts. Why is this error is thrown? I don't see any module dependency mentioned in the primeNG documentation https://www.primefaces.org/primeng/#/table.

Error:

Failed to compile.

./node_modules/primeng/components/dropdown/dropdown.js
Module not found: Error: Can't resolve '@angular/cdk/scrolling' in '/Users/admin/angular/MovieApp/node_modules/primeng/components/dropdown'

        import {TableModule} from 'primeng/table';
    ...
    imports: [
        BrowserModule,
        AppRoutingModule,
        HttpClientModule,CarouselModule,FieldsetModule,BrowserAnimationsModule,LightboxModule,
        ScrollPanelModule,TableModule
      ],...
5
did you try to install cdk? npm install @angular/cdk --save - Fateme Fazli
yes, I did, the compilation error is resolved. I will try to use in the component. Between I am trying to understand how is it dependent to TableModule while in the primeng documentation, it is mentioned as dependency: None. - javapedia.net
which version of angular and primeng are you using? - Fateme Fazli
"@angular/core": "~7.1.0", "primeicons": "^1.0.0", "primeng": "^7.1.0", - javapedia.net
see github.com/primefaces/primeng/commit/… primeng uses cdk as devDependencies in version 7.1.0. - Fateme Fazli

5 Answers

82
votes

Using npm install @angular/cdk --save would resolve this.

It needs it because the p-table uses the p-paginator which uses p-dropdown, which this needs the cdk.

You can check it here:

1
votes

Which angular version are you using. Angular 9 was removed ScrollDispatchModule in '@angular/cdk/scrolling' from last version. you can use it without importing the module . If not you can import the ScrollingModule instead.

0
votes

Just install a primeng version that is OK with your cdk, other way around. But changing your cdk version for primeng could mess with other dependencies and packages that you've already installed

0
votes

Check your "package.json"to confirm if "@angular/cdk" is installed. If its not, install it. If it is, press "CTRL C" to cut out and reserve with "ng serve"

-2
votes

ng add @angular/material

Choose a prebuilt theme name, or "custom" for a custom theme: Indigo/Pink

❯ Indigo/Pink [ Preview: https://material.angular.io?theme=indigo-pink ]
❯ Deep Purple/Amber [ Preview: https://material.angular.io?theme=deeppurple-amber ]
❯ Pink/Blue Grey [ Preview: https://material.angular.io?theme=pink-bluegrey ]
❯ Purple/Green [ Preview: https://material.angular.io?theme=purple-green ]
Choose Hammer.js (Gesture recognition support) and Angular browser animation service.
# Set up HammerJS for gesture recognition? (Y/n) = Y
# ? Set up browser animations for Angular Material? (Y/n) = Y