2

I tried to follow https://swiperjs.com/angular but I got this error, I also installed npm i @types/swiper but still the same error . Here is the error

ERROR in node_modules/swiper/angular/angular/src/swiper.component.d.ts:5:117 - error TS2307: Cannot find module 'swiper/types' or its corresponding type declarations.

5 import { SwiperOptions, SwiperEvents, NavigationOptions, PaginationOptions, ScrollbarOptions, VirtualOptions } from 'swiper/types';

my app module

import { SwiperModule } from 'swiper/angular';
@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule ,
    ReactiveFormsModule,
    HttpClientModule,
    SwiperModule
  ],

and in my global style, I added

@import "~@angular/material/theming";
@import '~swiper/swiper-bundle';
Mounaim
  • 61
  • 1
  • 7

1 Answers1

0

Here are some steps that I follow whenever I get these kind of errors.

  1. Re-build the project after importing the module, JIT sometimes fails
  2. Make sure the package was installed properly (The documentation says to install it with npm i swiper, try to use it instead of npm i @types/swiper, might work)
  3. Make sure the path from import exists and it points to a file
  4. Don't add imports manually, unless there is a strong reason for that. I use extensions like Auto-Import for VSCode which does the importing for me, I just have to write 'SwiperModule', and the import appears by itself.
Dorin Baba
  • 1,578
  • 1
  • 11
  • 23