next-themes icon indicating copy to clipboard operation
next-themes copied to clipboard

ThemeProvider returns multiple types

Open javi95z opened this issue 2 years ago • 9 comments

Type error: 'ThemeProvider' cannot be used as a JSX component. 
Its return type 'string | number | boolean | Iterable<ReactNode> | Element' is not a valid JSX element.

javi95z avatar Mar 22 '24 17:03 javi95z

For me, the problem was introduced: next-themes ^0.2.1 → ^0.3.0

Type error: 'ThemeProvider' cannot be used as a JSX component.
  Its return type 'string | number | boolean | Element | Iterable<ReactNode>' is not a valid JSX element.
    Type 'string' is not assignable to type 'ReactElement<any, any>'.

TomTom-Labs avatar Mar 28 '24 18:03 TomTom-Labs

@javi95z We need more information if we are to look into this. Can you please provide a reproduction? (Context: I have ~10 Next.js Apps on v14 with next-themes v0.3 running without any such issues)

trm217 avatar Apr 23 '24 08:04 trm217

Hello!

I have the same issue using

{
  "next-themes": "^0.3.0",
  "react": "^18.2.0", 
  "vite": "^5.2.8"
}

Downgrading next-themes to ^0.2.1 fixes the issue.

vshakun avatar May 03 '24 14:05 vshakun

Hey, I assume the issue is currently originating from here: https://github.com/pacocoursey/next-themes/blob/bf0c5a45eaf6fb2b336a6b93840e4ec572bc08c8/next-themes/src/index.tsx#L15

The type react node can be more things than just a JSX Element, so that is probably the issue (see https://reactnative.dev/docs/react-node).

I'll try to submit a PR to fix this issue

flixlix avatar Jun 27 '24 13:06 flixlix

I'm still encountering this error, any updates?

particle4dev avatar Aug 03 '24 12:08 particle4dev

Same here.

thedaviddias avatar Aug 03 '24 16:08 thedaviddias

To fix the issue you need to upgrade typescript to v5.1+ https://devblogs.microsoft.com/typescript/announcing-typescript-5-1-beta/#decoupled-type-checking-between-jsx-elements-and-jsx-tag-types

none23 avatar Aug 06 '24 13:08 none23

To fix the issue you need to upgrade typescript to v5.1+

Using typescript 5.5.3 and still seeing this issue...

evsasse avatar Aug 21 '24 13:08 evsasse

Here's a minimal demo: Codesandbox Downgrade typescript to "5.0.4" to see this error

none23 avatar Aug 22 '24 04:08 none23