0

I am trying to add/convert my existing react app (Almost empty) into typescript instead of JS. So based on some tutorials I have added a tsconfig.json into my project root with below contents

{
    "compilerOptions": {
      "outDir": "./dist/",
      "noImplicitAny": true,
      "module": "es6",
      "target": "es5",
      "jsx": "react",
      "allowJs": true,
      "moduleResolution": "node",
    }
  }

Then I installed typescript

npm install -g typescript

So what I did next is renamed my index.js as index.tsx and app.js and app.tsx and there is simple container component which I renamed to tsx as well.

But when I run the application by npm start its showing below error

enter image description here

I didnt get what I missed or what I did wrong. Very new to React.

1 Answer 1

2

Install types for the react

npm i -D @types/react @types/react-dom 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for that. It resolved this issue with a minor tweak. So changed it to import * as React from 'react'; import * as ReactDOM from 'react-dom/client';

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.