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

Viewed 8302

I am using material-ui in react with typescript template. All of my code is working fine but I am getting this error on multiple lines (not an error warning but with red line as my code renders)

Could not find a declaration file for module 'react/jsx-runtime'. 'C:/Users/dell/Desktop/Web current Projects/typescript/card/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`ts(7016)
5 Answers

As per @NearHuscarl's comment, a quick fix is to create your own declaration module for react/jsx-runtime. You can do this by opening the react-app-env.d.ts file (created by default when you use create-react-app), found in your project's root directory. Then add the following script to it:

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

The create-react-app team don't believe this is an issue for create-react-app to solve, and suggest it's a problem with typescript version 4. So alternatively you can downgrade your typescript version until the typescript team provide a fix in a later version.

When you have this error, it is usually because you installed a library and you didn't install the types of that library.

To fix this error, you need to install @types/library-name using your package manager (npm or yarn).

Came across this when trying to use create-react-app with typescript.

What solved it for me was changing the following file:

react-app-env.d.ts

/// <reference types="react-scripts" />

declare module 'react/jsx-runtime' {
  const content: string;
  export default content;
}

Try restarting vscode and see if it got fixed.

use yarn for manage package.

run this command

yarn install

Related