All Articles

Explained: Cannot use JSX unless the '--jsx' flag is provided

Matt Pocock
Matt PocockMatt is a well-regarded TypeScript expert known for his ability to demystify complex TypeScript concepts.

Cannot use JSX unless the '--jsx' flag is provided.

This error is likely happening because you haven't specified jsx in the compilerOptions of your tsconfig.json.

{
  "compilerOptions": {
    "jsx": "react"
  }
}

This option tells TypeScript that you're using JSX - the syntax that many frontend frameworks use to render elements.

Which value should I use for jsx?

There are several possible values you might need to consider for jsx. You can refer to my article solving the 'React refers to a UMD global' error for more information.

The most likely values to work are:

  • preserve: preserves the JSX as it is and doesn't add any extra transformations.
  • react-jsx: uses a modern transform (_jsx) that works with React 17 and above.
  • react: uses a legacy transform (React.createElement) that works with React 16 and below.

Try those in order, and see which one works for you.

And if you want to learn React and TypeScript more fully, check out my free React and TypeScript beginner's course. There are 21 interactive exercises packed with TypeScript tips and tricks for React apps.

Matt's signature

Explained: Cannot use JSX unless the '--jsx' flag is provided

Cursor Rules for Better AI Development

Finding existing community .cursor/rules for TypeScript lacking, I'm sharing my own set to hopefully kickstart a discussion on what makes effective AI coding guidance. These rules focus purely on TypeScript language features, documentation, structure (like Result types), teaching the AI specific nuances (like noUncheckedIndexedAccess), and practical habits, rather than specific frameworks. I also distinguish between shareable, project-specific Workspace Rules (versioned in Git) and personalized Global Rules (living in your IDE) to tailor the AI to your individual style and workflow. You can download my current ruleset using the link in the original post.

Matt Pocock
Matt Pocock

Should You Declare Return Types?

Here's a quick .cursor/rules addition you can make for handling return types in TypeScript.

# Return Types

When declaring functions on the top-level of a module,
declare their return types. This will help future AI
assistants understand the function's purpose.

```ts
const myFunc = (): string => {
  return "hello";
};
```

One exception to this is components which return JSX.
No need to
Matt Pocock
Matt Pocock

TypeScript Announces Go Rewrite, Achieves 10x Speedup

TypeScript announced a full rewrite of TypeScript in Go. In testing, this rewrite has achieved a 10x speedup in some repositories - and up to 15x in others.

Matt Pocock
Matt Pocock

TypeScript 5.8 Ships --erasableSyntaxOnly To Disable Enums

TypeScript 5.8's new erasableSyntaxOnly flag enforces pure type annotations by disabling enums, namespaces, and parameter properties.

Matt Pocock
Matt Pocock