Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Visual Studio to recognize the jsx setting from the tsConfig,json

I have a TypeScript/React project in Visual Studio.

The challenge is getting Visual Studio to recognize React.

IntelliSense errors in Visual Studio are of the form -

“--jsx is not set”,  “Cannot use JSX,  unless  the  ‘—jsx’ flag  is provided”

The obvious solution is to configure –-jsx.

There seems to be at least two way to do this -

  • Visual Studio project , Project properties -> TypeScript Build –> JSX Compilation in TSX files
  • tsConfig.json

    { "compilerOptions": {

    "jsx": "react",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true, 
    "noImplicitReturns": true,
    "target": "es5", ...
    

I have already configured -–jsx in tsConfig.json, and the command line gulp build works just fine, but Visual Studio still thinks that –jsx is not set.

So, for Visual Studio, I figured I could just set the project property ( in addition to tsconfig.json) But in Visual Studio this is disabled - “One or more tsconfig.json files detected. Project Properties are disabled”

enter image description here

How do I get Visual Studio to recognize the –jsx setting from the tsConfig,json. It seems to recognize that tsConfig.json exists , but does not specifically recognize that –jsx is configured

Dev Environment

  • Visual Studio: 2017 Professional
  • TypeScript : 2.1.4
  • React : 15.4.2
like image 595
Robotronic Avatar asked Sep 07 '17 16:09

Robotronic


People also ask

How do you fix Cannot use JSX unless the -- JSX flag is provided?

To solve the error "Cannot use jsx unless the '--jsx' flag is provided", restart your IDE and development server and make sure your IDE is using the same version of TypeScript that your project uses. The project's TypeScript version and your IDE's TypeScript versions should match.

What is Tsconfig JSON in react?

The tsconfig.json file specifies the root files and the compiler options required to compile the project. JavaScript projects can use a jsconfig.json file instead, which acts almost the same but has some JavaScript-related compiler flags enabled by default.


1 Answers

Historic question but still relevant today (at least to me...)

Solution: After setting "jsx": "react" in tsConfig.json restart Visual Studio.

like image 177
Jack Miller Avatar answered Oct 12 '22 23:10

Jack Miller