Create-react-app: TypeScript 4.1: Could not find a declaration file for module 'react/jsx-runtime'

Created on 20 Nov 2020  路  4Comments  路  Source: facebook/create-react-app

THIS IS NOT AN ISSUE WITH create-react-app; The typings for @types/[email protected] are not released yet and need to address this issue. The WIP can be found here. I already created a note for this issue on the PR.

I actually don't know whether this is an issue with the type definitions for react or react-scripts.

When upgrading to TypeScript 4.1.x I will get the following error:

Could not find a declaration file for module 'react/jsx-runtime'. '.../node_modules/react/jsx-runtime.js' implicitly has an 'any' type.
  If the 'react' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react`  TS7016

Adding the following to the react-app-env.d.ts resolved the issue, but feels hacky.

declare module "react/jsx-runtime" {
  export default any;
}

Would appreciate any information on whether that is an issue that needs to be solved within create-react-app or something that needs to be addressed by the type definitions.

Here the tsconfig.json for reference:

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

The behavior can be observed in this or build: https://github.com/n1ru4l/obs-character-info/pull/17

bug report needs triage

Most helpful comment

I鈥檓 getting this issue outside of CRA with Typescript 4.1.2

All 4 comments

I鈥檓 getting this issue outside of CRA with Typescript 4.1.2

For reference:

https://github.com/facebook/react/blob/89d4fe141a28b54807901126063249cab6483f89/packages/react/jsx-runtime.js#L1-L9

It seems like this must be addressed in the @types/react package.

I noted this on the PR for updating @types/react for [email protected] over here: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/48971#pullrequestreview-535291028

Gonna close this as it is not an issue related to create-react-app.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Aranir picture Aranir  路  3Comments

dualcnhq picture dualcnhq  路  3Comments

jnachtigall picture jnachtigall  路  3Comments

rdamian3 picture rdamian3  路  3Comments

wereHamster picture wereHamster  路  3Comments