formik icon indicating copy to clipboard operation
formik copied to clipboard

With React 19 typings: Cannot find namespace 'JSX'.

Open Philipp91 opened this issue 1 year ago • 5 comments

Bug report

Current Behavior

I use the latest formik release with React v19, specifically "@types/react": "^19.0.1" and I get 4 errors like:

node_modules/formik/dist/types.d.ts:209:109 - error TS2503: Cannot find namespace 'JSX'.

209 export type GenericFieldHTMLAttributes = JSX.IntrinsicElements['input'] | JSX.IntrinsicElements['select'] | JSX.IntrinsicElements['textarea'];

Expected behavior

No type errors.

Suggested solution(s)

s/JSX/React.JSX

Additional context

https://react.dev/blog/2024/04/25/react-19-upgrade-guide#the-jsx-namespace-in-typescript

It's only about typings anyway. In @react/types, this was backported also to the v16 series, so the proposed change doesn't require React v19 to work.

Your environment

Software Version(s)
Formik 2.4.6
React 19.0.0
TypeScript 5.5.4
npm/Yarn npm 10.9.0
Operating System Kubuntu

Philipp91 avatar Dec 07 '24 14:12 Philipp91

How did you install it ? I have peer problem while installing formik in react19 / nextjs15 Pretty much I have same environment as you have

image

FathZulfaAli avatar Dec 08 '24 10:12 FathZulfaAli

  "dependencies": {
    "formik": "^2.4.6",
    "react": "^19.0.0",
    "react-dom": "^19.0.0",
    ...
  },
  "devDependencies": {
    "@types/react": "^19.0.1",
    "@types/react-dom": "^19.0.1",
    ...
  },

Then npm install is happy to install exactly those versions that I asked for without complaints or warnings.

Philipp91 avatar Dec 08 '24 11:12 Philipp91

  "dependencies": {
    "formik": "^2.4.6",
    "react": "^19.0.0",
    "react-dom": "^19.0.0",
    ...
  },
  "devDependencies": {
    "@types/react": "^19.0.1",
    "@types/react-dom": "^19.0.1",
    ...
  },

Then npm install is happy to install exactly those versions that I asked for without complaints or warnings.

Lovely, thanks man,

Anyway I have another solution to overrides it with react

 "overrides": {
    "formik": {
      "react": "19.0.0-rc-66855b96-20241106",
      "react-dom": "19.0.0-rc-66855b96-20241106"
    }
  }

FathZulfaAli avatar Dec 12 '24 12:12 FathZulfaAli

Same issue for me

tva1992 avatar Jan 09 '25 16:01 tva1992

Replacing JSX with React.JSX worked for me in another project

escapedcat avatar Feb 12 '25 17:02 escapedcat

I was able to fix this for now by adding a global.d.ts with

declare global {
  namespace JSX {
    interface IntrinsicElements extends React.JSX.IntrinsicElements {}
  }
}

export {};

vollmerr avatar Sep 25 '25 22:09 vollmerr