22

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)
1
  • 1
    See this issue Commented Apr 12, 2021 at 7:36

9 Answers 9

44

Try restarting vscode and see if it got fixed

Sign up to request clarification or add additional context in comments.

3 Comments

My issue does not happen inside vscode. What now?
Works for Webstorm too
Your typescript language server needs restarting, so restart that if you can or restart the host (eg your IDE, or rerun the tsc command if it's CLI)
11

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.

Comments

10

npm i -D @types/react @types/react-dom

Did it for me.

Comments

7

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).

Comments

4

In my case it was caused by a version mismatch between the react/react-dom and @types/react/@types/react-dom packages.

Comments

2

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;
}

Comments

0

For me i fixed it by deleting this in tsconfig.json

"paths": {
  "*": ["./node_modules/*", "./src/types/*"],
}

Replaced with

"paths": {
  "react": ["./node_modules/@types/react"]
}

Comments

0

Update the following packages using npm or yarn

  • @types/react
  • @types/react-dom

after do Try restarting vs code and see if it got fixed

Comments

-7

use yarn for manage package.

run this command

yarn install

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.