I don't understand why it can't find it.
$ cat tsconfig.json { "compilerOptions": { "sourceMap": true, "target": "es6", "jsx": "react", "types": [ "lodash", "react", "react-dom" ] } } $ tree node_modules/@types node_modules/@types/ ├── lodash │ ├── README.md │ ├── index.d.ts │ ├── package.json │ └── types-metadata.json ├── react │ ├── README.md │ ├── index.d.ts │ ├── package.json │ └── types-metadata.json └── react-dom ├── README.md ├── index.d.ts ├── package.json ├── server.d.ts └── types-metadata.json
Importing in a component file.
// src/components/component.tsx import * as React from "react";
What gives?
To solve the error "Cannot find module 'react/jsx-runtime' or its corresponding type declarations", make sure to install the typings for react running the command npm install --save-dev @types/react@latest @types/react-dom@latest and restart your dev server.
The error "could not find declaration file for module 'react'" occurs when TypeScript cannot find the type declaration for a react-related module. To solve the error install the types for the module by running the command from the error message, e.g. npm install -D @types/react . Copied!
The "Cannot find module or its corresponding type declarations" error occurs when TypeScript cannot locate a third-party or local module in our project. To solve the error, make sure to install the module and try setting moduleResolution to node in your tsconfig. json file.
To solve the error "Module not found: Error: Can't resolve 'react-dom'", make sure to install the react-dom package by opening your terminal in your project's root directory and running the command npm install react-dom react and restart your development server.
I had the same issue. You just need to install @types:
npm i -D @types/react
if you're not using typescript 2.1, you should upgrade to it. it looks like you're using a 2.x version from the @types you have there.
here is a working tsconfig.json
file that i'm using right now:
{ "compilerOptions": { "target": "es6", "module": "commonjs", "moduleResolution": "node", "noResolve": false, "noImplicitAny": false, "removeComments": true, "sourceMap": true, "allowJs": true, "jsx": "react" }, "exclude": [ "./node_modules/**/*" ] }
it's been a couple days since i resolved the same issue you were having, but i think the key here is the "moduleResolution": "node"
and "allowJs": true
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With