LoginSignup
3
1

More than 5 years have passed since last update.

rails 5.1 babel-preset-env "Missing class properties transform" の回避

Last updated at Posted at 2017-04-20

rails5.1でreactを書いていてこういうエラーが出る場合

1__bin_webpack-dev-server__node_.png

解決方法

dalmatian__Git_.png

stage-0stage-1またはstage-2config/loaders/react.jsに入れる

なぜこれで直るのか?

rails5.1ではデフォルトで babel-preset-envを使用していて、書かれているようにstage-0stage-1stage-2..のようなpluginは含まれない。

It won't include stage-x plugins. env will support all plugins in what we consider the latest version of Javascript (by matching what we do in babel-preset-latest).

プラグインは実験的なものも多く、stageが上がるほどより洗練されて行っている
stage-0 > stage-1 > ...
つまりdeprecatedなpluginはstageが0に行くほど多い

Stage_2_preset_·_Babel.png

今回問題のSyntaxError: Missing class properties transform.はtransform-class-propertiesが入っていない事が問題で、これはstage-2に含まれており、それ以前のstageにも含まれている(要は01

だから結果として適切なstage-xを入れるとコンパイルエラーが無くなる

babel-preset-env

参考: http://qiita.com/ryuone/items/13f5d450c3865709ba10

この問題の解決方法を探す間に.babelrcを簡単に書くサイトを見つけたので紹介

QA方式で.babelrcとnpm、yarnのインストールコマンドラインが表示される
_babelrc_-_Config_Wizard.png

3
1
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
3
1