2017-01-10 2 views
0

私のReactプロジェクトでデコレータを使用しようとしていて、.babelrcのプラグインを参照しているバベルプラグインをインストールしましたが、私のコンソールに。Babelが正しいプラグインにもかかわらずデコレータ構文をコンパイルできません

package.json

// ... 
    "devDependencies": { 
    "babel-plugin-transform-decorators-legacy": "^1.3.4", 
    "babel-plugin-transform-object-rest-spread": "^6.16.0", 
    "chai": "^3.5.0", 
    "file-loader": "^0.9.0", 
    "url-loader": "^0.5.7" 
    } 
// ... 

.babelrc - 私は、以前transform-object-rest-spreadプラグインがインストールされていたので、ちょうどplugins配列に拡張している:で、

{ 
    "plugins": ["transform-object-rest-spread", "transform-decorators-legacy"] 
} 

とコンソールのエラーを(念のため)フル:

BabelLoaderError: SyntaxError: Decorators are not officially supported yet in 6.x pending a proposal update. 
However, if you need to use them you can install the legacy decorators transform with: 

npm install babel-plugin-transform-decorators-legacy --save-dev 

and add the following line to your .babelrc file: 

{ 
    "plugins": ["transform-decorators-legacy"] 
} 

The repo url is: https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy. 

私は何をしないのですか?

+2

私はあなたの応答を受け取ったのと同様に、おっと – azium

+0

同様にあなたのWebPACKの設定を投稿私はそれを解決しました:)答えを見て... – Paulos3000

答えて

0

(aziumが指摘したように)私は.babelrcなくwebpack.config.jsにプラグインが含まれていました。私はこれを含めた場合

、それが働いた:

// ... 
query: { 
    plugins: [ 'transform-decorators-legacy' ] 
} 
// ... 

希望を誰がこの問題に遭遇した場合に役立つこと:)

+1

これは優先されますか? '.babelrc'ファイルまたは' webpack'のバベル設定?それをマージしますか? – lux

+0

それは素晴らしい質問です。いいえアイデアは - しかし... – Paulos3000

+1

ああ、興味深い知りたいんです。 、WebPACKのにfalse'のその場合には、それが唯一の_really_のWebPACKの設定を使用します。私たちは 'bablercを追加することができますように見えます。それとは別に、何が起こるかまだ分かりません! https://gist.github.com/rmoorman/94eeed830942758e218d92f15ce58d88 – lux

関連する問題