Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import swiper not working #501

Open
ayesha-waris opened this issue Aug 27, 2021 · 9 comments
Open

import swiper not working #501

ayesha-waris opened this issue Aug 27, 2021 · 9 comments

Comments

@ayesha-waris
Copy link

my react version is 17 and i'm not able to import swiper

@brunolcarlos
Copy link

I have the same problem ./node_modules/react-id-swiper/lib/ReactIdSwiper.js
Module not found: Can't resolve 'swiper' in

@snovosel
Copy link

also not working for me either

@benistary
Copy link

Same

2 similar comments
@Gofack
Copy link

Gofack commented Sep 8, 2021

Same

@aminghe
Copy link

aminghe commented Sep 11, 2021

Same

@snovosel
Copy link

I've found that downgrading the package to the last major version fixed the issue for me

@vicki-unitek
Copy link

which version

@anuragsinghbam
Copy link

which version

There is some issue with the new version 7.0.6 of swiper.
So to go back to the previous version of the swiper use this command.

npm install [email protected]

And use this syntax to import.


import { Swiper, SwiperSlide } from 'swiper/react'
import SwiperCore, { Navigation, Pagination, Controller, Thumbs } from 'swiper'
import 'swiper/swiper-bundle.css'

SwiperCore.use([Navigation]);

And to use it follow this syntax.

const App = () => (
  <div className='hero-section'>
    <Swiper navigation={true} className='mySwiper'>
      <SwiperSlide>Slide 1</SwiperSlide>
      <SwiperSlide>Slide 2</SwiperSlide>
      <SwiperSlide>Slide 3</SwiperSlide>
      <SwiperSlide>Slide 4</SwiperSlide>
    </Swiper>
   </div>
)

export default App

@TianxiangHan
Copy link

which version

There is some issue with the new version 7.0.6 of swiper. So to go back to the previous version of the swiper use this command.

npm install [email protected]

And use this syntax to import.


import { Swiper, SwiperSlide } from 'swiper/react'
import SwiperCore, { Navigation, Pagination, Controller, Thumbs } from 'swiper'
import 'swiper/swiper-bundle.css'

SwiperCore.use([Navigation]);

And to use it follow this syntax.

const App = () => (
  <div className='hero-section'>
    <Swiper navigation={true} className='mySwiper'>
      <SwiperSlide>Slide 1</SwiperSlide>
      <SwiperSlide>Slide 2</SwiperSlide>
      <SwiperSlide>Slide 3</SwiperSlide>
      <SwiperSlide>Slide 4</SwiperSlide>
    </Swiper>
   </div>
)

export default App

Just adding on top of anuragsinghbam's answer. if you want to use the pagination, Autoplay or FadeEffect onto the slides,
just to add them in SwiperCore.use()
and then pass them as props as following:
SwiperCore.use([Navigation,Pagination,EffectFade,Autoplay]);
<Swiper

            modules={[Navigation, Pagination,EffectFade,Autoplay]}
             effect={"fade"}//there are effects of 'slide' | 'fade' | 'cube' | 'coverflow' | 'flip' | 'creative' | 'cards'
            spaceBetween={50}// space between slides
            slidesPerView={4} // useful if your slides is cards
            centeredSlides={true}
            pagination={{ clickable: true }}   //pagination 
            autoplay={{delay: 1000,disableOnInteraction: false,}}      
            onSlideChange={() => console.log("slide change")}
            onSwiper={swiper => console.log(swiper)}
            className="mySwiper"
            
>
          <SwiperSlide ><img /></SwiperSlide>
          <SwiperSlide ><img /></SwiperSlide>
          <SwiperSlide ><img /></SwiperSlide>
          <SwiperSlide ><img /></SwiperSlide>
          <SwiperSlide><img /></SwiperSlide>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants