With this code:
import React from 'react';
import { Link } from 'react-router';
import { View, NavBar } from 'amazeui-touch';
import * as Pages from '../components';
const { Home, ...Components } = Pages;
I get this eslint error:
7:16 error Parsing error: Unexpected token .. Why?
Here is my eslint config:
{
"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
}],
}
}
.... .... What's the problem?
If you have got a pre-commit task with husky running
eslint
, please continue reading. I tried most of the answers aboutparserOptions
andparser
values where my actual issue was about the node version I was using.My current node version was 12.0.0, but husky was using my nvm default version somehow (even though I didn't have
nvm
in my system). This seems to be an issue with husky itself. So:$HOME/.nvm
folder which was not deleted when I removednvm
earlier.In my case (im using Firebase Cloud Functions) i opened
.eslintrc.json
and changed:to:
I solved this issue by First, installing babel-eslint using npm
Secondly, add this configuration in .eslintrc file
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
in ES6 classes as ESLint is currently unable to parse it on its own. This particular situation will throw an error of:
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:
to your
.eslintrc
file and runnpm install babel-eslint --save-dev
oryarn 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.ESLint 2.x experimentally supports ObjectRestSpread syntax, you can enable it by adding the following to your
.eslintrc
: docsESLint 1.x doesn't natively support the spread operator, one way to get around this is using the babel-eslint parser. The latest installation and usage instructions are on the project readme.
"parser": "babel-eslint"
helped me to fix the issueReference