[BUG] TypeScript Error in React 17 Due to React.JSX Reference
Bug description After upgrading to the latest version of react-tooltip, I encountered a TypeScript error in the library’s type definitions. The issue is caused by a reference to React.JSX in the TooltipWrapper declaration, which is not supported in React 17 projects using @types/react v17. Upon investigation, I noticed that starting from [email protected], the library updated its @types/react dev dependency from 18.0.28 to ^18.2.17. This change introduces compatibility issues for projects still using @types/react v17. Could you please confirm if this dependency bump is strictly necessary? Upgrading @types/react in my current setup is not straightforward.
Environment
- React version: 17.0.2
- React DOM version: 17.0.2
- React Tooltip version: 5.28.1
- @types/react version: 17.x
To Reproduce
- Use a React 17 project with this tsconfig.json:
{
"compilerOptions": {
"target": "ESNext",
"moduleResolution": "Node",
"allowJs": false,
"noEmit": true,
"strict": true,
"jsx": "react",
"esModuleInterop": true,
"resolveJsonModule": true,
"module": "CommonJS",
"noErrorTruncation": true,
"types": [
"node"
],
"forceConsistentCasingInFileNames": true
}
}
- Install [email protected].
- Run tsc.
Expected behavior No errors to be reported. Typescript should build successfully
Actual Behavior
Error: node_modules/react-tooltip/dist/react-tooltip.d.ts:250:193 - error TS2694: Namespace 'React' has no exported member 'JSX'.
I'm not sure how relevant it would be for us to provide this level of backwards compatibility, but we will keep it mind.
A relatively easy fix in your case would be to use something like patch-package to fix it "manually" (substitute the React.JSX references to use the old syntax) in that specific codebase.
Let us know if that works for you.
Hi @gabrieljablonski, thanks for the quick reply and suggestions!
Using patch-package isn’t a viable option in my specific case, as there are other projects consuming the components, and I’d need to ensure that those projects also install it for the patch to take effect consistently. While it technically works, it’s not practical in my setup.
At this point, I’m leaning toward reverting to an earlier version of the react-tooltip library—one that doesn’t include the @types/react changes.
This issue is stale because it has not seen activity in 30 days. Remove the stale label or comment within 14 days, or it will be closed.