59

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
      ],...
halfer
  • 19,824
  • 17
  • 99
  • 186
javapedia.net
  • 2,531
  • 4
  • 25
  • 50

7 Answers7

119

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:

Daniel Piñeiro
  • 3,009
  • 1
  • 16
  • 26
  • 2
    Worked for me, but I also had to restart my IDE afterwards before it was picked up, a recompilation and restart of processes wasn't enough (using WebStorm) – Peter Andreas Moelgaard May 13 '20 at 02:22
  • 1
    So, installing npm modules that require cdk do not result in cdk being install if it is needed? – Display name Apr 10 '21 at 20:15
  • 1
    strange, I think prime-ng should at least list @angular/cdk as a peer dependency in its package.json. Or mention in the docs that the CDK needs to be installed. Not so dev-friendly to let everyone run into that error when using the Table module. – spierala Jun 12 '21 at 08:37
2

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.

CodeMind
  • 616
  • 1
  • 7
  • 19
1

enter image description here

Just un update

When you import the PrimeNg 13.0.3 TableModule in your Angular 13.1.0, is enough to break the compiler because the module is still dependent on @angular/cdk/scrolling.

To solve, you need to install angular/cdk, as already mentioned in the accepted response.

javapedia.net
  • 2,531
  • 4
  • 25
  • 50
0

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

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"

Ib Abayomi Alli
  • 361
  • 3
  • 6
-2

Regarding to the primeNg documentation you need to install CDK package:

npm install @angular/cdk --save

Also, you can check this page: https://primefaces.org/primeng/#/dropdown

Hamid
  • 761
  • 7
  • 18
-3

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

S sabeer
  • 39
  • 2
  • 5
  • 1
    This is obviously copied from [here](https://www.positronx.io/angular-8-drag-and-drop-tutorial-with-example/). [From Review](https://stackoverflow.com/review/low-quality-posts/24991982). – Wai Ha Lee Jan 03 '20 at 00:13