<Component /> throws a type error in pages/_app.tsx
Unanswered
Rule posted this in #help-forum
RuleOP
Hi. I'm getting this error on my ./pages/_app.tsx file from <Component />
What could be wrong?
What could be wrong?
import type { AppProps } from "next/app";
interface PageProps {
user?: AuthUser;
}
const App = ({ Component, pageProps }: AppProps<PageProps>) => {
return <Component {...pageProps} />
}TS2786: 'Component' cannot be used as a JSX component. Â Â Its element type 'Component<any, any, any> | ReactElement<any, any> | null' is not a valid JSX element. Â Â Â Â Type 'Component<any, any, any>' is not assignable to type 'Element | ElementClass | null'. Â Â Â Â Â Â Type 'Component<any, any, any>' is not assignable to type 'ElementClass'. Â Â Â Â Â Â Â Â The types returned by 'render()' are incompatible between these types. Â Â Â Â Â Â Â Â Â Â Type 'React.ReactNode' is not assignable to type 'import("C:/Users/User/PhpstormProjects/project/web/node_modules/@types/react/ts5.0/index").ReactNode'. Â Â Â Â Â Â Â Â Â Â Â Â Type 'ReactElement<any, string | JSXElementConstructor<any>>' is not assignable to type 'ReactNode'. Â Â Â Â Â Â Â Â Â Â Â Â Â Â Property 'children' is missing in type 'ReactElement<any, string | JSXElementConstructor<any>>' but required in type 'ReactPortal'. index.d.ts(160, 9): 'children' is declared here.5 Replies
maybe your
@types/ packageRuleOP
I tried to play around with it, upgrade different versions but didnt help:
"next": "^13.4.19",
"react": "18.2.0",
"react-dom": "18.2.0",
"@types/react": "18.2.0",
"@types/react-dom": "18.2.0",RuleOP
I tried that. It also happens when building for production
Ah solved by updating to these types
"@types/node": "20.5.9",
"@types/react": "18.2.21",
"@types/react-dom": "18.2.7",