How to fix Cannot use JSX unless the ‘ — jsx’ flag is provided.ts(17004)

I recently encountered the following error whilst working on a Typescript react project in VS Code. There are various solutions online which tell you to modify the “jsx” field in tsconfig.json which works until you run npm start again in which you will find that the “jsx” field in tsconfig.json has reverted back to “react-jsx” again

The fix is actually specific to VS Code and requires you to simply change the typescript version by looking it up in the command palette (Ctrl + Shift + P)

and selecting “Use workspace version”

After selecting the use workspace option all the errors disappeared, and I’ve encountered this issue several times.

The error message itself presented is quite hard to figure out, so hopefully this article will help some people fix their issue!

© 2021 Louis Kueh