DevLoverUmar
DevLoverUmar

Reputation: 13923

React Project not compiling after adding TypeScript

I'm getting a strange error as

./src/index.js Line 56:15: Parsing error: '>' expected

I followed the official guide by create-react-app for Adding TypeScript to my existing Create React App project. And after changing just the two .js files(index and App) to .tsx, the project compilation is getting failed.

I uninstalled the global create-react-app by following this troubleshooting guide

index.tsx file

import React from "react";
import ReactDOM from "react-dom";
ReactDOM.render(
  <App store={store} persistor={persistor} basename={PUBLIC_URL} />,
  document.getElementById("root")
);

Note: I have changed my index.js file to index.tsx but still getting error for index.js. I guess it's throwing error after compilation to .js

Upvotes: 0

Views: 1341

Answers (2)

DevLoverUmar
DevLoverUmar

Reputation: 13923

After a useless struggle of 3 hours I found the root cause of error :)

As I mentioned earlier in the question I removed global create-react-app package to avoid problems but that created the problem. I don't know why but when, I reinstalled the create-react-app, the problem is resolved!

Upvotes: 0

basarat
basarat

Reputation: 276181

/src/index.js Line 56:15: Parsing error: '>' expected

You are using JSX in a .js file. Rename the file to .jsx (or even better `.tsx).

More

You can compare to a TypeScript app by npx create-react-app example --template typescript 🌹

Upvotes: 2

Related Questions