下面的代码:

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

import * as Pages from '../components';

const {  Home, ...Components } = Pages;

我得到这个eslint错误:

7:16  error  Parsing error: Unexpected token .. Why?

这是我的eslint配置:

{
  "extends": "airbnb",
  "rules": {
    /* JSX */
    "react/prop-types": [1, {
      "ignore": ["className", "children", "location", "params", "location*"]
    }],
    "no-param-reassign": [0, {
      "props": false
    }],
    "prefer-rest-params": 1,
    "arrow-body-style": 0,
    "prefer-template": 0,
    "react/prefer-stateless-function": 1,
    "react/jsx-no-bind": [0, {
      "ignoreRefs": false,
      "allowArrowFunctions": false,
      "allowBind": true
    }],
  }
}

.... .... 有什么问题吗?


当前回答

在2021年2月,你可以使用这些值

ecmaVersion -设置为3,5(默认),6,7,8,9,10,11或12,以指定您想使用的ECMAScript语法版本。也可以设置为2015(与6相同)、2016(与7相同)、2017(与8相同)、2018(与9相同)、2019(与10相同)、2020(与11相同)或2021(与12相同)。

https://eslint.org/docs/user-guide/configuring/language-options#specifying-parser-options

其他回答

"parser": "babel-eslint"帮我解决了这个问题

{
    "parser": "babel-eslint",
    "parserOptions": {
        "ecmaVersion": 6,
        "sourceType": "module",
        "ecmaFeatures": {
            "jsx": true,
            "modules": true,
            "experimentalObjectRestSpread": true
        }
    },
    "plugins": [
        "react"
    ],
    "extends": ["eslint:recommended", "plugin:react/recommended"],
    "rules": {
        "comma-dangle": 0,
        "react/jsx-uses-vars": 1,
        "react/display-name": 1,
        "no-unused-vars": "warn",
        "no-console": 1,
        "no-unexpected-multiline": "warn"
    },
    "settings": {
        "react": {
            "pragma": "React",
            "version": "15.6.1"
        }
    }
}

参考

React + Firebase函数

转到:functions -> .eslintrc.js

添加它- parserOptions: { ecmaVersion: 8, 的,

module.exports = {
  root: true,
  env: {
    es6: true,
    node: true,
  },
  parserOptions: {
    ecmaVersion: 8,
  },
  extends: ["eslint:recommended", "google"],
  rules: {
    quotes: ["error", "double"],
  },
};

最初,解决方案是提供以下配置,因为对象解构曾经是一个实验特性,默认情况下不支持:

{
  "parserOptions": {
    "ecmaFeatures": {
      "experimentalObjectRestSpread": true
    }
  }
}

从版本5开始,该选项已弃用。

现在只要声明一个ES的新版本就足够了:

{
  "parserOptions": {
    "ecmaVersion": 2018
  }
}

我必须将ecmaVersion更新为“最新”

"parserOptions": {
    "parser": "@babel/eslint-parser",
    "sourceType": "module",
    "ecmaVersion": "latest",
    "ecmaFeatures": {
      "jsx": true,
      "experimentalObjectRestSpread": true
    },
    "requireConfigFile": false
  },

尽管实现了上述所有解决方案,但我还是遇到了这个问题。当我降级eslint版本时,它开始工作了