11

I have a NextJS React Application 17.0.2 that declares a bunch of providers before rendering the individual page.

Inside of my ./src/pages/_app.tsx, I have the following code-snippet:

<ExistingPortfolioProvider registry={registry}>
    <CrankProvider>
        <Component {...pageProps} />
    </CrankProvider>
</ExistingPortfolioProvider>

this code snippet runs on my development environment (when running next dev). When I upload this to vercel, however, I get the following error.

Type error: 'Component' cannot be used as a JSX component.
  Its element type 'ReactElement<any, any> | Component<{}, any, any> | null' is not a valid JSX element.
    Type 'Component<{}, any, any>' is not assignable to type 'Element | ElementClass | null'.
      Type 'Component<{}, 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("/vercel/path0/dapp-nextjs/node_modules/@types/react-transition-group/node_modules/@types/react/index").ReactNode'.
            Type '{}' is not assignable to type 'ReactNode'.
              Type '{}' is missing the following properties from type 'ReactPortal': key, children, type, props
  52 |                                             <ExistingPortfolioProvider registry={registry}>
  53 |                                                 <CrankProvider>
> 54 |                                                     <Component {...pageProps} />
     |                                                      ^
  55 |                                                 </CrankProvider>
  56 |                                             </ExistingPortfolioProvider>
  57 |                                         </UserWalletAssetsProvider>
error Command failed with exit code 1.

Any idea why this could be, or how I can debug this? I have already double-checked that each individual provider does return children like so:

    return (
        <>
            <ILocalKeypairContext.Provider value={value}>
                {props.children}
            </ILocalKeypairContext.Provider>
        </>
    );

The view it is trying to render also only has a single component that's returning a single node (with multiple children).

Any ideas what else I could be looking into?

--- UPDATE 1 ---

I edited the code to get a "minimum example",

   9 |     return (
  10 |         <>
> 11 |             <Component {...pageProps} />
     |              ^
  12 |         </>
  13 |     );

still getting the same issue. Is this because of some NextJS stuff where renders have to be server-side or so?

--- UPDATE 2 ---

It fails on my laptop too now. I deleted the nextjs cached, yarn.lock and now got to reproduce it locally.

--- UPDATE 3 ---

I came across this beautiful thread https://github.com/facebook/react/issues/24304 but the proposed solution of adding "preinstall": "npx npm-force-resolutions" does not work for me on yarn (it looks for a package-json.lock for some reason)

8
  • seems a syntax error between CrankProvider component, where "^" symbol is typed. Commented Apr 12, 2022 at 13:04
  • @p4avinash how do you see this? xD Commented Apr 12, 2022 at 13:05
  • hmm, CrankProvider doesn't seem to have any syntax errors .. Commented Apr 12, 2022 at 13:08
  • <Component {...pageProps} /> can you try changing the name of the Component to something else like <ComponentTest {...pageProps} /> for time being and check. I was able to resolve my issues with similar problem Commented Apr 12, 2022 at 13:15
  • @ChannaveerHakari I changed it to <MyComponent {...pageProps} /> (from <Component {...pageProps} />). I am not importing the props like this function MyApp({Component: MyComponent, pageProps}: AppProps) (I cannot straight-out redefine the types in AppProps). I seemed to make go away the error from before, but now I am getting new errors ... Will see how much I can debug on the new ones Commented Apr 12, 2022 at 13:29

4 Answers 4

20

I upgraded my "@types/react" version to 18.0.1 and it worked. Did you try this?

Sign up to request clarification or add additional context in comments.

1 Comment

Just as a heads up if you are using turbo repo, you will have to update the @types/react and @types/react-dom in all of your apps/packages as having multiple version of @types/react will cause the error to persist.
14

I removed the @types/react dependency that was in version 17.0.3, and added it again current version 18.0.9, It worked successfully 🤗

yarn remove @types/react
yarn add @types/react -D

Comments

5

Adding


"resolutions": {
    "@types/react": "^17.0.38"
  },

did the trick. I'm using yarn

Comments

0

I updated Next.js to 12.1.6 and it worked (I removed yarn.lock and installed again with yarn install). This is my package.json:

{
  "name": "javier-portfolio",
  "version": "0.4.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@ajna/pagination": "^1.4.17",
    "@chakra-ui/icons": "^2.0.1",
    "@chakra-ui/react": "^1.8.8",
    "@emotion/react": "11",
    "@emotion/styled": "11",
    "framer-motion": "6",
    "next": "12.1.6",
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
  },
  "devDependencies": {
    "@types/node": "^17.0.19",
    "@types/react": "^17.0.30",
    "eslint": "7.32.0",
    "eslint-config-next": "11.1.2",
    "eslint-config-prettier": "^8.3.0",
    "typescript": "^4.4.4"
  },
  "resolutions": {
    "@types/react": "^17.0.30"
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.