question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

THIS 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:closed
  • Created 3 years ago
  • Reactions:28
  • Comments:20 (4 by maintainers)

github_iconTop GitHub Comments

84reactions
robvanderleekcommented, Dec 30, 2020

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.

42reactions
aguilaredcommented, Jan 15, 2021

Solve with> rm -rf node-modules, rm -rf package-lock.json, yarn install, and yarn add @types/react --dev

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: TypeScript 4.1: Could not find a declaration file for ...
Error: TypeScript 4.1: Could not find a declaration file for module 'react/jsx-runtime' Jayesh Tiwari. 教學. This episode is also available as a blog...
Read more >
Could not find declaration file for module 'react' | bobbyhadz
The error "could not find declaration file for module 'react'" occurs when TypeScript cannot find the type declaration for a react-related module.
Read more >
create-react-app 17 with Typescript 4.1 | by Jay - Medium
I have been planning to start using React JS with TypeScript. ... Could not find a declaration file for module 'react/jsx-runtime'.
Read more >
TSConfig Option: jsxImportSource - TypeScript
Declares the module specifier to be used for importing the jsx and jsxs ... jsx as "react-jsx" or "react-jsxdev" which were introduced in...
Read more >
cannot find module '@emotion/react/jsx-runtime' or its ...
If you're using TypeScript you might have run into this error before. The second part of the error says: Try `npm install @types/XYZ`...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found