Typescript with tsx error

Hi i have phpstorm where React written in .ts and .tsx files is compiled through babel in webpack.

I cant get editor to work, it marks my tsx syntax as wrong because allegedly:
`TS17004: Cannot use JSX unless the '--jsx' flag is provided.`

 

I tried to do it with and without `tsconfig.json` with this content

```

{
"jsx": true,
"comment": "Only for phpstorm highlighting, not actually used in compiling",
"compilerOptions": {
"jsx": "react"
},
"include": [
"www/js/ts/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}

```

but nothing changed, can you please help me?

 

PHPStorm 2020.1.1

 

8 comments
Comment actions Permalink

Adding

"jsx": "react"

to

"compilerOptions": {}

in tsconfig.json should do the thing (placing it outside this section is not permitted)

How many tsconfig.*.json files do you have in your project? Is your .tsx file included in any of them?

0
Comment actions Permalink

I have exactly that in compilerOptions secttion, nothing changes if i remove first line, my config looks like this now:

I have only `tsconfig.json` in root directory, nothing else in project matches that pattern.

 

0
Comment actions Permalink

Please attach s screenshot of Typescript error console with the error message.

0
Comment actions Permalink

can't reproduce with similar configurtion

please share a sample project the issue can be repeated with

0
Comment actions Permalink

Well this is kind of weird, i was setting the sample project and my original project started working just ok, no wrong errors. It works either with or without `tsconfig.json`.

 

SInce i cannot reproduce the issue i guess this is all. Thank you for your time.

 

1
Comment actions Permalink

I'm having the same issue in WebStorm 2021.2.3. The problematic files are named like `BarChart.spec.tsx`.

We have "**/*.spec.*" listed under "exclude" in tsconfig.json. Removing that made the error go away. But I don't think that's a proper solution, just a workaround.

0
Comment actions Permalink

I had similar issue with WebStorm 2021.2.3. I was working on a Lerna monorepo. My issue was the editor has picked up Typescript from another module instead the one I was working. So pointing correct TS version fixed everything. Also I was having TSLint not found error and that also fixed

 

 

0

Please sign in to leave a comment.