Eslint parsing error: Keyword "import" is reserved


#1

Hi,

Using Atom for Meteor development, but this error always occurs:

Eslint Error Fatal: Keyword “import” is reserved

The code: import { Accounts } from 'meteor/accounts-base';

Any idea how to get rid of the error?

Thanks!


#2

You need to update your eslint config and have it support the ES6+ syntax. Google is your friend :slight_smile: As a side note, instead of using the eslint parser, I use babel-eslint as my parser and eslint-config-airbnb-base as the base config that’s extended and modified to suite my taste.

Here’s some code to give you the idea https://github.com/steelbrain/eslint-config-steelbrain


#3

I created an account just to comment on this.

“Google is your friend” !? Please, please assume that we all know and already have access to Google…

I have this same error… and I’ve spent almost a whole day trying to fix it… of course I’m using Google.

Your response doesn’t actually answer the question! And, the github link you provide doesn’t have any information about babel-eslint, or how to update the config to have it support the ES6+ syntax.

Having the steelbrain installation instructions, I still have this error in Atom.


#4

I acknowledge that I did not go into the deepest of details on how to fix that. Let me try once more

There are different revisions of Javascript (or more accurately ECMAScript). The import keyword is a recent addition to the standard, therefore on parsers that follow the older revisions of the syntax, it would simply not work.

If you are on the latest version of ESLint, you should not run into this issue. As the ESLint readme specifies, If something new is accepted into the ECMA standard, ESLint will try to adopt it or start accepting pull requests for it.

The “README” of the project also mentions how you could use babel-eslint as the parser (setup section of babel-eslint README) to support syntax not natively available in ESLint.

So to recap, You need to make sure you’re on the latest version of ESLint, if it still doesn’t work for you, install babel-eslint and configure it in your .eslintrc.[whatever format you use] to be the parser and it should work for you.

If it doesn’t work, then something is not working as intended and you should open issues in relevant repositories with adequate information so the devs can try to reproduce the problem on their end and fix the issue.


#5

Wow, thank you for the excellent response!

That actually worked!

I think what was missing is that I needed to update my eslint and/or babel-eslint. I ran

npm install eslint@6.x babel-eslint@8 --save-dev

And my config file now looks like

{
“parser”: “babel-eslint”,
“extends”: [“eslint:recommended”, “google”]
}

Things are working now! Hurrah!!!