LoginSignup
18
4

More than 3 years have passed since last update.

TSでReactの環境構築中に出た "error Cannot use JSX unless the '--jsx' flag is provided." を解消する

Last updated at Posted at 2021-05-06

症状

src/app.tsx:10:17 - error TS17004: Cannot use JSX unless the '--jsx' flag is provided.

10 const element = <h1>Hello, world</h1>;

Typescriptを使ってReactの環境を作っているときに発生したエラーです。

結論:下記のいずれかで治ると思います

1.使用しているtypescriptのバージョンを4.1以上にする
2.tsconfig.json で compilerOptions.jsx = react-jsx とする

1.使用しているtypescriptのバージョンを4.1以上にする

詳細は「VScodeでTSを使うと出るCannot use JSX unless the '--jsx' flag is provided. ts(17004)を解決する。」などをご参照ください。
なお、自分の場合はこれでは直らなかった。というより、エラー発生時点で既に4.1以上を使っていた。そんなときは下記2を試してみましょう。

2.tsconfig.json で compilerOptions.jsx = react-jsx とする

tsconfig.json
{
  "compilerOptions": {
    "jsx": "react-jsx",
  }
}

参考:"Error: Cannot use JSX unless the '--jsx' flag is provided" when using "extends"

自分の場合はこれで治った。

18
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
4