YIZHUANG / react-multi-carousel

A lightweight production-ready Carousel that rocks supports multiple items and server-side rendering with no dependency. Bundle size 2kb.
MIT License
1.25k stars 286 forks source link

'Carousel' cannot be used as a JSX component #346

Closed jason-liu22 closed 1 year ago

jason-liu22 commented 2 years ago

2022-05-31_03-21 2022-05-31_03-13

Could someone help me, please?

react-multi-carousel@^2.8.0

Thanks in advance.

vladimirmyshkovski commented 2 years ago

Same error with the same version.

vladimirmyshkovski commented 2 years ago

@pyDjangoDev remove node_modules directory and yarn.lock or package-lock.json file and reinstall dependencies. In my case it's solve the problem.

jason-liu22 commented 2 years ago

I just tried to do it in that way. but I still get the same error. Anyway, thanks @vladimirmyshkovski

shaffi-ahuja commented 2 years ago

@pyDjangoDev Were you able to resolve this issue... I am also facing the same

Marthijs-Berfelo commented 1 year ago

@pyDjangoDev @shaffi-ahuja I encountered the same issue with an older version however only when running a different NODE version.

UPDATE

even NODE versions v16.15.0 and v16.15.1 work for me.

MuizU commented 1 year ago

@pyDjangoDev @shaffi-ahuja I encountered the same issue with an older version however only when running a different NODE version.

  • using latest LTS: v16.16.0 the problem occurred
  • using older version: v16.10.0 no problem

UPDATE

even NODE versions v16.15.0 and v16.15.1 work for me.

This didn't work for me despite using all three versions.

rortan134 commented 1 year ago

Try adding <></> (React.Fragment) wrapping the {} as a workaround like this:

<Carousel >
  <>
     {avatars.map((_) =>  /*...*/ )}
  </>
</Carousel />

See more: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18051#issuecomment-567690424

jason-liu22 commented 1 year ago

Try adding <></> (React.Fragment) wrapping the {} as a workaround like this:

<Carousel >
  <>
     {avatars.map((_) =>  /*...*/ )}
  </>
</Carousel />

See more: DefinitelyTyped/DefinitelyTyped#18051 (comment)

jason-liu22 commented 1 year ago

@pyDjangoDev Were you able to resolve this issue... I am also facing the same

I didn't resolve it at that moment. so I used the react-slick, an alternative.

MuizU commented 1 year ago

It worked for me after I upgraded @types/react to 18.0.1

sssuho commented 1 year ago

write this code on the Component

{/ @ts-expect-error Server Component /} <CarouselPosts />

eucciferri commented 1 year ago

In my case I was able to solve this problem by updating the dependencies of the packages, executing the command: yarn upgrade

zhenglib commented 1 year ago

I had same issue, and I solved it with node v 16.13.0

  1. Remove node_modules
  2. nvm use 16.13.0
  3. npm i --save
  4. npm start

This solved my issue.