TypeScript 4.1: Could not find a declaration file for module 'react/jsx-runtime'
See original GitHub issueTHIS IS NOT AN ISSUE WITH create-react-app; The typings for @types/react@17.x.x
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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:28
- Comments:20 (4 by maintainers)
Top GitHub Comments
FWIW, ran into this issue after a Dependabot version bump to TypeScript 4.1.3 and
yarn add @types/react --dev
was enough to resolve the compilation error.Solve with> rm -rf node-modules, rm -rf package-lock.json, yarn install, and yarn add @types/react --dev