react-tooltip icon indicating copy to clipboard operation
react-tooltip copied to clipboard

'ReactTooltip' cannot be used as a JSX component.

Open nosnaj opened this issue 6 years ago • 14 comments

(alias) class ReactTooltip
import ReactTooltip
'ReactTooltip' cannot be used as a JSX component.
  Its instance type 'ReactTooltip' is not a valid JSX element.
    Type 'ReactTooltip' is missing the following properties from type 'ElementClass': render, context, setState, forceUpdate, and 3 more.ts(2786)

Can't seem to use it as just in my tsx code.

nosnaj avatar Aug 06 '20 04:08 nosnaj

Same here. Am I doing something wrong?

einord avatar Aug 25 '20 14:08 einord

Just get your colleague to do it on their machine. That's how I got it to work... I don't know what the hell happened lol.

On Tue, Aug 25, 2020, 22:21 Jonatan Nyqvist [email protected] wrote:

Same here. Am I doing something wrong?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/wwayne/react-tooltip/issues/624#issuecomment-680055407, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANHXUQ3V4K7R5BRNBGHTYDSCPCFXANCNFSM4PWFBTJA .

nosnaj avatar Aug 25 '20 21:08 nosnaj

Hey guys! Could you share how you solved it? I am having the same issue here... Thanks!

claudebarde avatar Aug 26 '20 09:08 claudebarde

Hi, I'm @nosnaj's colleague mentioned here (thanks a lot). Just to note, we're using this package without@types/react-tooltip installed.

node version: 12.18.3 //if it matters react-tooltip version: ^4.2.8

Here's basically what we're doing

import ReactTooltip from 'react-tooltip';

const Component = () => {
  return (
    <>
      {/** can be any element (i think) */
      <div data-tip="tip: there's no tip">
        hover me to see the tip
      </div>
      <ReactTooltip />
    </>
  )
}

It's actually the same as the readme, I just checked. You might want to check tsconfig.json, and your package.json versions.

Here's our tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react",
    "baseUrl": "src"
  },
  "include": ["src"]
}

and our package.json dependencies and devDependencies, obviously without secret information 😉 (note, some packages are not needed, I'm not sure which)

{
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "@types/jest": "^26.0.7",
    "@types/node": "^14.0.26",
    "@types/react": "^16.9.43",
    "@types/react-dom": "^16.9.8",
    "node-sass": "^4.14.1",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-router-dom": "^5.2.0",
    "react-scripts": "3.4.1",
    "react-tooltip": "^4.2.8",
    "typescript": "^3.9.7",
  },
  "devDependencies": {
    "@types/jest": "^26.0.7",
    "@types/node": "^14.0.26",
    "@types/prop-types": "^15.7.3",
    "@types/react": "^16.9.43",
    "@types/react-dom": "^16.9.8",
    "@types/react-router-dom": "^5.1.5",
    "@typescript-eslint/parser": "^3.7.1",
    "babel-eslint": "^10.1.0",
    "eslint-config-react-app": "^5.2.1",
    "eslint-plugin-import": "^2.22.0",
    "eslint-plugin-jsx-a11y": "^6.3.1",
    "eslint-plugin-react": "^7.20.3",
    "husky": "^4.2.5",
    "prettier": "^2.0.5",
    "pretty-quick": "^2.0.1",
    "typescript": "^3.9.7"
  },
  //other stuff here
}

alex93293 avatar Aug 26 '20 11:08 alex93293

Great, thank you, I will give it a try!

claudebarde avatar Aug 26 '20 11:08 claudebarde

Simply npm i -D @types/react-tooltip resolved this issue for me. Not sure why alex93293 didn't have it installed, unless I missed something in this conversation.

lieuweberg avatar Feb 03 '21 10:02 lieuweberg

I'm still having this problem with Next.js whether or not I have @types/react-tooltip installed.

Here's my tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "~/*": [
        "./*"
      ]
    },
    "jsxImportSource": "@emotion/react",
    "target": "es2017",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "noImplicitAny": false,
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "plugins": [
      {
        "name": "typescript-plugin-tw-template"
      }
    ],
    "incremental": true
  },
  "typeRoots": [
    "node_modules/@types",
    "@types"
  ],
  "include": [
    "next-env.d.ts",
    "**/*.js",
    "**/*.jsx",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules",
  ]
}

tettoffensive avatar Apr 14 '22 23:04 tettoffensive

Facing same issue, any solution will be helpful!

ronakiihglobal avatar Apr 15 '22 13:04 ronakiihglobal

+1

Similar issue here. Just popped up this morning. Wondering if it was some downstream dependency that changed. Here is the full stack trace:

'ReactTooltip' cannot be used as a JSX component.
  Its instance type 'ReactTooltip' is not a valid JSX element.
    The types returned by 'render()' are incompatible between these types.
      Type 'React.ReactNode' is not assignable to type 'import("/Code/interface/node_modules/@types/react-helmet/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

Edit: This solved my issue - https://stackoverflow.com/questions/71791347/npm-package-cannot-be-used-as-a-jsx-component-type-errors/71828113#71828113

redhair avatar Apr 15 '22 13:04 redhair

I'm still having this issue with Next js and TS even though I installed @types/react-tooltip. It was working before so not sure what changed in the package now but getting the same error.

judygab avatar Apr 25 '22 17:04 judygab

Same issue here. Even with @types/react-tooltip installed.

mosesweb avatar May 19 '22 14:05 mosesweb

Add this to your package.json

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

From https://stackoverflow.com/questions/71791347/npm-package-cannot-be-used-as-a-jsx-component-type-errors/71828113#71828113

kheengz avatar Nov 25 '22 17:11 kheengz

I tried resolutions and installing @types/react-tooltip but still have this error.

vijayth2-cerebras avatar Dec 20 '22 00:12 vijayth2-cerebras

Hey, @vijayth2-cerebras. Just in case you're not in the loop, react-tooltip v5 got released recently (you can check the details here).

We recommend migrating to it, since support was dropped for v4.

In case you're not able to migrate to v5, or run into any other problems, feel free to open a new issue.

gabrieljablonski avatar Dec 20 '22 00:12 gabrieljablonski