I have looked around a bit for a solution to this problem. All of them suggest adding "jsx": "react"
to your tsconfig.json file. Which I have done. Another one was to add "include: []"
, which I have also done. However, I am still getting the error when I am trying to edit .tsx
files. Below is my tsconfig file.
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"allowJs": true,
"checkJs": false,
"jsx": "react",
"outDir": "./build",
"rootDir": "./lib",
"removeComments": true,
"noEmit": true,
"pretty": true,
"skipLibCheck": true,
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true
},
"include": [
"./lib/**/*"
],
"exclude": [
"node_modules"
]
}
Any suggestions would be helpful. I am using babel 7 to compile all the code with the env, react and typescript presets. If you guys need more files to help debug this, let me know.
Restarting my IDE in my case was the fix.After restarting a message box popped up and it was showing that i don't have any typescript installed, would you like to install TypeScript 3.3? I installed it and now its working perfectly.See here for output window
This link was helpful to resolve this issue: https://staxmanade.com/2015/08/playing-with-typescript-and-jsx/
Refer the section: Fixing error TS17004: Cannot use JSX unless the '--jsx' flag is provided.
The next error is new to me, but it makes some sense, so I add the --jsx flag to tsc and try tsc --jsx helloWorld.tsx, but looks like I missed a parameter to --jsx.
preserve will keep the jsx in the output. I presume this is so you can use tools like JSX to actually provide the translation. react will remove the jsx syntax and turn it in to plain javascript so in the TSX file would become React.createElement("div", null). By passing the react option, here's where we end up:
I was getting this error even when running
npx tsc --jsx preserve
so the--jsx
was definitely specified.In my case this was caused by having
incremental: true
in the tsconfig. Apparently in incremental modetsc
may ignore the--jsx
setting, and use information from previous builds instead (where--jsx
was still disabled). As a solution I turned of incremental compilation temporarily, recompiled, and re-enabled it. Probably deleting the build artifacts might also work.In my case the issue was the VSCode generated an empty
tsconfig.json
file which, of course, did nothing.I added this to
tsconfig.json
from Typescript's React Page:{ "compilerOptions": { "outDir": "./dist/", "sourceMap": true, "noImplicitAny": true, "module": "commonjs", "target": "es6", "jsx": "react" } }
...then hit
save
and VSCode took it from there. Problem solved.In my case, I tried all the
tsconfig.json
, Project Properties dialog, restarting IDE, checking installed TypeScript version, etc, and it still had this error. Come to find out the dev that made the project added conditional properties to the project file, such thatTypeScriptJSXEmit
is not defined in all configurations (which confused the Project Properties dialog).Here's an excerpt from my project file showing the issue:
Restart your IDE. Sometimes tsconfig.json changes aren't immediately picked up