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

@types/react installation mismatch #7227

Closed
1 of 2 tasks
bobbysciacchitano opened this issue Dec 6, 2024 · 11 comments
Closed
1 of 2 tasks

@types/react installation mismatch #7227

bobbysciacchitano opened this issue Dec 6, 2024 · 11 comments

Comments

@bobbysciacchitano
Copy link

Dependencies check up

  • I have verified that I use latest version of all @mantine/* packages

What version of @mantine/* packages do you have in package.json?

7.14.3

What package has an issue?

@mantine/core

What framework do you use?

Next.js

In which browsers you can reproduce the issue?

Not applicable – issue is not related to the browser

Describe the bug

I'm currently building a menu component and came across this exception why trying to build (TS):

Type error: 'Menu.Target' cannot be used as a JSX component.
  Its type 'ForwardRefExoticComponent<MenuTargetProps & RefAttributes<HTMLElement>>' is not a valid JSX element type.
    Type 'ForwardRefExoticComponent<MenuTargetProps & RefAttributes<HTMLElement>>' is not assignable to type '(props: any) => ReactNode'.
      Type 'import("/Users/bobby/Documents/Development/embark/node_modules/@mantine/core/node_modules/@types/react/index").ReactNode' is not assignable to type 'React.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'.

This is my example implementation which I could reproduce the issue:

import { Button, Menu } from "@mantine/core";

type EntrySettingsProps = {
  form: Partial<SessionEntry | ProgramEntry>;
  onChange: OnFormChange;
  validation: ValidationErrors;
};

export function EntrySettings({}: EntrySettingsProps) {
  return (
    <Menu>
      <Menu.Target>
        <Button>Toggle menu</Button>
      </Menu.Target>
      <Menu.Dropdown>
        <Menu.Item>Testing</Menu.Item>
      </Menu.Dropdown>
    </Menu>
  );
}

package.json file:

  "dependencies": {
    "@mantine/core": "^7.14.3",
    "@mantine/hooks": "^7.14.3",
    "date-fns": "^4.1.0",
    "next": "15.0.4",
    "react": "19.0.0",
    "react-dom": "19.0.0"
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^19",
    "@types/react-dom": "^19",
    "eslint": "^8",
    "eslint-config-next": "15.0.4",
    "postcss": "^8.4.49",
    "postcss-preset-mantine": "^1.17.0",
    "postcss-simple-vars": "^7.0.1",
    "prettier": "^3.3.3",
    "typescript": "^5"
  }

If possible, include a link to a codesandbox with a minimal reproduction

No response

Possible fix

No response

Self-service

  • I would be willing to implement a fix for this issue
@rtivital
Copy link
Member

rtivital commented Dec 6, 2024

@rtivital rtivital closed this as completed Dec 6, 2024
@kenzaflow
Copy link

After update to React 19:

This is also happening in Vite (SPA), even with MenuTarget (no Menu.Target)

Only in that component

image

'MenuTarget' cannot be used as a JSX component.
  Its type 'ForwardRefExoticComponent<MenuTargetProps & RefAttributes<HTMLElement>>' is not a valid JSX element type.
    Type 'ForwardRefExoticComponent<MenuTargetProps & RefAttributes<HTMLElement>>' is not assignable to type '(props: any) => ReactNode'.
      Type 'import(".../node_modules/@mantine/core/node_modules/@types/react/index").ReactNode' is not assignable to type 'React.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'.ts(2786)

@bobbysciacchitano
Copy link
Author

bobbysciacchitano commented Dec 6, 2024

Having reviewed the documentation, adding "use client" to the start of the module still causes an exception for me.

Screenshot 2024-12-07 at 12 14 58 AM Screenshot 2024-12-07 at 12 15 13 AM

Build time error:

Type error: 'Menu.Target' cannot be used as a JSX component.
  Its type 'ForwardRefExoticComponent<MenuTargetProps & RefAttributes<HTMLElement>>' is not a valid JSX element type.
    Type 'ForwardRefExoticComponent<MenuTargetProps & RefAttributes<HTMLElement>>' is not assignable to type '(props: any) => ReactNode'.
      Type 'import("/Users/bobby/Documents/Development/embark/node_modules/@mantine/core/node_modules/@types/react/index").ReactNode' is not assignable to type 'React.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'.
"use client";

import { Button, Menu } from "@mantine/core";

type EntrySettingsProps = {
  form: Partial<SessionEntry | ProgramEntry>;
  onChange: OnFormChange;
  validation: ValidationErrors;
};

export function EntrySettings({}: EntrySettingsProps) {
  return (
    <Menu> 
      <Menu.Target>
        <Button>Button</Button>
      </Menu.Target>

      <Menu.Item>Hello World</Menu.Item>
    </Menu>
  );
}

@rtivital rtivital reopened this Dec 6, 2024
@rtivital
Copy link
Member

rtivital commented Dec 6, 2024

Okay, this is a ts issue, probably with @types/react. Can you reproduce it in codesandbox?

@kenzaflow
Copy link

kenzaflow commented Dec 6, 2024

I just tried with vite-min-template and nothing, I'm going to try with the one with eslint

Edit: also not a problem with vite-template

Here is the sandbox with vite-template + latest react (all dependencies updated with npx npm-check-updates && yarn install)

https://codesandbox.io/p/github/kenzaflow/vite-template/master?import=true

@rtivital
Copy link
Member

rtivital commented Dec 8, 2024

Try adding resolutions to your package.json and reinstall dependencies:

"resolutions": {
  "@types/react": "19.0.1",
  "@types/react-dom": "19.0.1"
}

@dincerpece
Copy link

I installed only nextjs and mantine. I encountered the same problem in codesandbox.io. Then I installed it with yarn and built it and it worked without any problems.

yarn before:
before

yarn after:
after

https://codesandbox.io/p/github/dincerpece/mantine-react19-test/draft/distracted-feistel?workspaceId=ws_JmivbuKahEgQ2p1ZSV2BLi

@dincerpece
Copy link

Similarly, there was a problem locally before Yarn, but after the installation with Yarn, the problem disappeared. I hope it will be fixed without the need for an installation with Yarn.

local yarn before:
before yarn

local yarn after:
after yarn

@bobbysciacchitano
Copy link
Author

Setting the resolutions to the suggested versions in yarn resolved my issue.

@felix-fuin
Copy link

felix-fuin commented Dec 10, 2024

"resolutions": {
  "@types/react": "19.0.1",
  "@types/react-dom": "19.0.1"
}

This solution works. (it should match versions installed)
And for those working with npm:

"overrides": {
  "@types/react": "19.0.1",
  "@types/react-dom": "19.0.1"
}

@rtivital
Copy link
Member

The issue is not related to Mantine. If you see this message, it means that there are two conflicting versions of @types/react are installed. To fix it:

  • With yarn and probably with pnpm
"resolutions": {
  "@types/react": "19.0.1",
  "@types/react-dom": "19.0.1"
}
  • WIth npm:
"overrides": {
  "@types/react": "19.0.1",
  "@types/react-dom": "19.0.1"
}

@rtivital rtivital changed the title [Mantine 7.14.3 / NextJS 15.0.4 / React 19.0] Menu.Target typescript error @types/react installation mismatch Dec 10, 2024
@rtivital rtivital pinned this issue Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants