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

Typescript error with Next13, Monorepo (turbo repo), and Async components #55080

Closed
1 task done
dannytlake opened this issue Sep 6, 2023 · 3 comments · Fixed by #57259
Closed
1 task done

Typescript error with Next13, Monorepo (turbo repo), and Async components #55080

dannytlake opened this issue Sep 6, 2023 · 3 comments · Fixed by #57259
Labels
bug Issue was opened via the bug report template. locked TypeScript Related to types with Next.js.

Comments

@dannytlake
Copy link

dannytlake commented Sep 6, 2023

Link to the code that reproduces this issue or a replay of the bug

https://github.com/dannytlake/next-13-turbo-async-bug

To Reproduce

Note, the reference repo was created by running pnpm dlx create-turbo@latest

  1. in VSCode, clone repo
  2. Install dependencies
  3. In apps/web/app/page.tsx, the async component AsyncComponent should be causing a typescript error on line 62.

'AsyncComponent' cannot be used as a JSX component. Its return type 'Promise<Element>' is not a valid JSX element. Type 'Promise<Element>' is missing the following properties from type 'ReactElement<any, any>': type, props, keyts(27
When setting VSCode to use the workspace typescript version by running TypeScript: Select TypeScript Version... and choosing workspace version of 5.2.2, the error persists.

image

image

Current vs. Expected behavior

When building a nextjs application inside a monorepo, there should be no typescript error when using an async component inside a RSC component in the App Router

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 20.6.0: Wed Nov 10 22:23:07 PST 2021; root:xnu-7195.141.14~1/RELEASE_X86_64
    Binaries:
      Node: 18.14.0
      npm: 9.3.1
      Yarn: 1.22.19
      pnpm: 8.6.6
    Relevant Packages:
      next: 13.4.20-canary.18
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 4.9.5
    Next.js Config:
      output: N/A

Which area(s) are affected? (Select all that apply)

App Router, TypeScript (plugin, built-in types)

Additional context

This doesn't seem to be related specifically to VSCode, I had folks open the repo in webstorm as well and they experienced the same issue.

@dannytlake dannytlake added the bug Issue was opened via the bug report template. label Sep 6, 2023
@github-actions github-actions bot added the TypeScript Related to types with Next.js. label Sep 6, 2023
@timmeade
Copy link

I just updated a working turbo repo from 13.4.3 i think to 13.5.3 and now almost every shadcn component is kicking this out.

'Dialog' cannot be used as a JSX component.
  Its type 'FC<DialogProps>' is not a valid JSX element type.
    Type 'FunctionComponent<DialogProps>' is not assignable to type '(props: any, deprecatedLegacyContext?: any) => ReactNode'.

There are a TON of them.

@darcy-vitacca
Copy link

darcy-vitacca commented Oct 24, 2023

upgrade @types/react fixed this

leerob added a commit that referenced this issue Oct 27, 2023
### What?
When I ran `npx create-next-app --example with-turbopack` and installed
dependencies using `yarn`, I found an typescript error(`'SomeComponent'
cannot be used as a JSX component.`).

<img
src="https://github.com/vercel/next.js/assets/51700274/f6c7e478-c0b1-4ea2-996f-4c0c78e3bb4b"
width=400 />

and I realized that the bug is due to the version of
@types/react(18.0.x).
you can check this issue on
[here](#42292 (comment))
too.

### Why?
It seems that there is an error occurring in the @types/react version
18.0.x.

### How?
It would be good to change the @types/react version to 18.2.8 in the
next.js examples.

I think this change will resolve [this
issue](#55080 (comment))
[NestJS
documentation](https://nextjs.org/docs/app/building-your-application/configuring/typescript#async-server-component-typescript-error)
also states to upgrade the version.

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked TypeScript Related to types with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants