ESLint Parsing error: Unexpected token

后端 未结 8 2025
野趣味
野趣味 2020-11-28 02:12

With this code:

import React from \'react\';
import { Link } from \'react-router\';
import { View, NavBar } from \'amazeui-touch\';

import * as Pages from \         


        
8条回答
  •  旧巷少年郎
    2020-11-28 03:09

    Unexpected token errors in ESLint parsing occur due to incompatibility between your development environment and ESLint's current parsing capabilities with the ongoing changes with JavaScripts ES6~7.

    Adding the "parserOptions" property to your .eslintrc is no longer enough for particular situations, such as using

    static contextTypes = { ... } /* react */
    

    in ES6 classes as ESLint is currently unable to parse it on its own. This particular situation will throw an error of:

    error Parsing error: Unexpected token =
    

    The solution is to have ESLint parsed by a compatible parser. babel-eslint is a package that saved me recently after reading this page and i decided to add this as an alternative solution for anyone coming later.

    just add:

    "parser": "babel-eslint"
    

    to your .eslintrc file and run npm install babel-eslint --save-dev or yarn add -D babel-eslint.

    Please note that as the new Context API starting from React ^16.3 has some important changes, please refer to the official guide.

提交回复
热议问题