TypeScript module not found in React?

Viewed 37

I tried adding typescript in my create-react-app project by renaming the .js files into .tsx and by installing it throught the CL like this:

npm install --save typescript @types/node @types/react
npm install --save typescript @types/react-dom @types/jest

but when i restart the dev server i get the error "Compiled with problems: X ERROR in ./src/index.tsx 7:0-24 Module not found: Error: Can't resolve './App' in 'C:\Users\user\Downloads\React\project\src' "

this is index.tsx:

import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

reportWebVitals();

How can i fix this?

1 Answers

Did you try these two steps?

  1. add TypeScript to the Project

    npm install --save typescript @types/node @types/react @types/react-dom @types/jest

  2. add the tsconfig.json

    npx tsc --init

Related