LoginSignup
78
60

More than 5 years have passed since last update.

ESLintで Parsing error: Unexpected token = となる場合の対処法

Last updated at Posted at 2018-01-31

2018/2/1
誤った理解でしたのでタイトルと内容を修正いたしました。
@mysticatea さんご指摘ありがとうございました!

事象

以下のようなコードに対して、ESLintを掛けた所、

Example.jsx
class Account extends React.PureComponent {
  // ここでパースエラー
  handleOpenAddDialog = () => {
    this.setState({ isAddDialogOpen: true })
  }
}
Parsing error: Unexpected token =

というerrorが発生した。

原因

  • ESLint標準のパーサーでは、まだ標準化されていないクラスフィールド構文は扱えないため

解決方法

babel-eslintをパーサーに指定することにより、解決できる。

npm install babel-eslint --save-dev

を実行。

そして、.eslintrc.jsonに "parser": "babel-eslint"を加筆

.eslintrc.json
{
    "parser": "babel-eslint",
    // 以下、設定が続く…
}

そして、ESLintを実行すればパースエラーがなくなる。

./node_modules/.bin/eslint --ext .js --ext .jsx ./

参考にさせて頂いた記事

babel な ESLint の設定をがんばった

78
60
3

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
78
60