LoginSignup
4
2

More than 5 years have passed since last update.

babel-polyfill使ってるのにTravisCIでregeneratorRuntime is not definedが発生したときの対処

Posted at

はじめに

最近開発を進めている redux-tower というRedux向けのルーティングライブラリでは AVA をテストランナーとして使っているのですが、TravisCI をセットアップした際に起こった問題とその対処についてメモを残しておきます。

問題

redux-tower ではライブラリを使用するアプリ側で babel-polyfill をインポートすることを想定しています。そのため、テストする際にも、テスト側で babel-polyfill をインポートしていました。

src/__tests__/preprocess.js
import 'babel-polyfill'; 
import test from 'ava'; 

// ...

ローカル環境ではそれで問題なくテストを実行できていたんですが、TravisCI 上で実行してみるとエラーが発生しました。

  ✔ actions › createActionCreator
  ✔ utils › isReactComponent
  ✔ actions › createActionCreatorArgs
  ✖ preprocess › preprocess - flat Error: regeneratorRuntime is not defined
  ✖ preprocess › preprocess - nested Error: regeneratorRuntime is not defined

抜粋: https://travis-ci.org/kuy/redux-tower/jobs/187996280

あれっと思って確認してみましたが、preprocess.js ではちゃんとインポートしていました。

対処方法

個別にテストファイル内で babel-polyfill をインポートするのをやめて、AVA のオプションで require するように変更したら解消しました。もちろんローカルでの動作も問題なし。

  },
  "ava": {
    "require": [
      "babel-register",
      "babel-polyfill"
    ],
    "babel": "inherit"
  }
}

抜粋: https://github.com/kuy/redux-tower/blob/master/package.json#L71

原因

原因不明です。ローカルの環境では発生しなかったので TravisCI 特有の何か、ということくらいしかわかりません。

感想

すでに Node.js が Generator をサポートしているので babel-plugin-transform-regenerator を使わなければいいんじゃね?ってのは去年から考えているんですが、Babel 6 からブラックリストが無くなったので個別にプラグイン設定するのが面倒で試していません。スタックトレースもキレイになるし。そういうpresetを定義すればいいのかな。

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