LoginSignup
5
4

More than 3 years have passed since last update.

asyncを使用したコードをjestでテストすると「regeneratorRuntime is not defined」エラーが発生

Posted at

確認環境

  • Node.js: 10.16.0
  • Jest: 24.9.0
  • @babel/core: 7.7.5

エラー内容

jestでテスト実行すると、asyncの記述の部分で、以下のようなエラーが発生しました。

    ReferenceError: regeneratorRuntime is not defined

       9 | }
      10 | 
    > 11 | const main = async () => {
         |              ^

対応

.babelrcにて、babelのターゲットを指定することで解決しました。
変更前:

.babelrc
{
  "presets": [
    "@babel/preset-env"
  ]
}

変更後:

.babelrc
{
  "presets": [
    [
      "@babel/preset-env", {
        "targets": {
          "node": "current"
        }
      }
    ]
  ]
}

以上。

5
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
5
4