1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[JEST] Support for the experimental syntax 'jsx' isn't currently enabled が出たときの解消メモ

Posted at

エラー内容

React コンポーネントを Jest でテストしようとすると、次のようなエラーが出ることがあります。 JSX をそのまま書いているだけなのに Jest が理解できず、テストが失敗してしまいます。

SyntaxError: Support for the experimental syntax 'jsx' isn't currently enabled

原因

Jest は JSX をそのまま理解できないため,JSX を JavaScript に変換する設定が必要になる。

以下のような場合、この設定が無いためエラーが発生する。

  • Babel の設定を入れていない
  • @babel/preset-react を使用していない

解決方法

Rootフォルダにbabel.config.jsonを作成し以下のコードを導入する

{
  "presets": [
    "@babel/preset-env",
    [
      "@babel/preset-react",
      {
        "runtime": "automatic"
      }
    ]
  ]
}
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?