2

I installed the most recent .NET Core SDK. From Visual Studio (NOT VS Code) I chose the ASP.NET Core React template. The web site runs fine. Great. But when I try to use TypeScript I run into problems:

  1. When I add a .tsx file, I get a compilation error. Cannot use JSX unless the '--jsx' flag is provided.

  2. When I try to use Jest by typing npm test from the command line, it runs tests. Good. But when I put a test into a TypeScript file, I get compilation errors like Cannot find name expect. When I try to use instructions for using TypeScript with Jest I start running into compilation errors complaining about my package.json - These options in your package.json Jest configuration are not currently supported by Create React App.

Aren't these templates supposed to provide a ready-to-go works-out-of-the-box experience? I can't believe that what I'm trying to do here is unusual - using Jest with TypeScript and using TypeScript to define a TSX component. The create-react-app template with typescript provides these facilities without ANY hassles. It just works. Am I doing something wrong here? Am I not understanding the purpose of ASP.NET Core? I want to be able to build my front-end with React and have a nice C#-backed solid web site inside a project I can build and debug with Visual Studio. Too much to ask?

2 Answers 2

1

It looks like there are some hacks to get TypeScript to work with React and asp.net core like react-app-rewired. My honeymoon with React is over because I am a big fan of TypeScript and rxjs too. Time to explore Angular.

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

Comments

1

I've struggled significantly with the templates as well. I also work in typescript with react/.net core.

  1. When I create a new project I will initiate it as new react / .net core project through visual studio.
  2. The clientapp folder will be javascript so I delete the entire ClientApp folder.
  3. Navigate to the project folder and type in npm create-react-app clientapp --typescript.

It should now work out of the box if you start the project in visual studio. The application will work because the startup.cs file is pointing to the right build folder that the react template is configured to compile to.

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.