エンジニアの覚え書き

web系エンジニアの技術メモを主に投稿していきます。

Babel7にバージョンアップ時に辿り着いたissueとworkaroundな対応メモ

Babel7にバージョンアップした際に、あれこれ調べてworkaroundな対応を行ったメモ。

storybook

regeneratorRuntime is not definedというエラーになるので、addons.jsconfig.js@babel/polyfillをimportするようにした。

github.com

※issueの内容自体はbabel7と関係ないけど、これで上手くいったので引用。

// .storybook/addons.js, .storybook/config.js
import '@babel/polyfill';

lint

TypeError: Cannot read property 'range' of nullになるので、eslintの設定を.eslintrcに切出しして、一時的にindenttemplate-curly-spacingをoffにした。

github.com github.com

    "rules": {
        "template-curly-spacing": "off",
        "indent": "off",
    }

build + jest

jest側はbabel.config.jsに設定を切り出ししないとbuildに失敗するが、babel-node側ではbabel.config.jsを参照してくれない場合があるため(dockerでbabel-node build的な処理を行った場合に発生した)、babel.config.jsを追加してpackage.jsonの設定を参照するようにした。

github.com

// babel.config.js
const pkg = require('./package.json');

module.exports = {
  presets: pkg.babel.presets,
  env: pkg.babel.env,
  plugins: pkg.babel.plugins,
};