134

I am getting the linting error in my code 'import' is only available in ES6 (use 'esversion: 6').

Everything es6 related is throwing an error. Not sure what I have to configure to get it to work.

Gama11
34.7k9 gold badges92 silver badges107 bronze badges
asked Mar 30, 2016 at 20:17

7 Answers 7

263

Add a file named .jshintrc to your project and inside this file type this:

{
 "esversion": 6
}

As you can see it here:

enter image description here

The full documentation of jshint options are found here: http://jshint.com/docs/options

Josh
2,4922 gold badges28 silver badges19 bronze badges
answered Mar 30, 2016 at 20:27
Sign up to request clarification or add additional context in comments.

5 Comments

jshint.com/docs/options/#esversion for those looking for the documentation.
This should be added automatically.
seems like at times you need to add this line "moz": true
This didn't work for me (vscode version 1.37.1, OS X). Go to the extension preferences --> select Edit in settings.json To the JSON add: "jshint.options": { "esversion": 6 } Don't forget the comma on the previous line!
The only place to add this is in ~/settings.json in my experience. Project level settings won't affect it. It is absurd this isn't the default. It is really hard to find out how to fix this and in the meantime the user experience with javascript in VS Code is hostile. Super annoying. It should support ES6+ by default. Why wouldn't it?
131

Edit: I've added a way to enable es6 if you use ESLint instead of JSHint as well as updating the screenshots since VSCode has changed since my original answer.

JSHint Method:

If you are using JSHint, you can add the following to your settings:

"jshint.options":{
 "esversion":6
}

ESLint Method:

If you are using ESLint, you can add the following to your settings:

"eslint.options": {
 "env":{
 "es6":true
 },
 "parserOptions": {
 "ecmaVersion": 6 // or 7,8,9
 }
}

ESLint Configuration Documentation

How to update the settings

  1. Neither JSHint or ESLint are enabled in a fresh version of VS Code, so you'll need to install the extension(s) by going to extensions and then searching for your preferred linter.

  2. In VS Code, head to settings

VS Code Settings

  1. When the settings display you'll see the settings sections:

User and Workspace Settings Tabs

Note that there are two sections where you can customize your settings, User Settings and Workspace Settings

User Settings Is where you should apply any global settings you will want for any project you will ever work on.

Workspace Settings Is where you can make settings changes that should only be applied to your current project.

In my case, since I know that only some of my projects can use ES6, I need to have the error hinting to warn me if I'm using ES6 my non-ES6 projects...so I set this only to my Workspace Settings

But, if you know that anything you code in VS Code is going to be an ES6, project, then save a step, and add it to your user settings.

  1. Click on either User/Workspace depending on your preference. Search for JSHint or ESLint (whichever you use). Click on any of the Edit in settings.json links, it doesn't matter which one.

Edit in settings.json

  1. Add the pertinent settings depending on whether you use JSHint or ESLint:

JSHint

Adding the JSHint Setting

ESLint

Adding the ESLint Setting

answered Feb 18, 2018 at 5:03

5 Comments

This was a great answer and +1 for not having to create an additional file within project directories...Screenshots also very helpful, thank you so much!
Also this is better as can be done automatically for new projects, instead of creating new files, or just kept within a single workspace.
Doesn't work for me for some reason. I tried it in both user and workspace settings
Thank you so much for a detailed explanation, it was very helpful indeed.
Thank you. Following code worked for me. "jshint.options":{ "esversion":6 }
27

You can add "esversion": 6 to "jshint.options" in the user settings.

{
 "jshint.options": {
 "esversion": 6
 }
}
answered Dec 28, 2017 at 14:22

1 Comment

mine has another entry "jshint.config": "", just add "jshint.options": { "esversion": 6 } afterwards do not confuse.
14

Just to round out the excellent suggestions already submitted, you can also set this on a file by file basis by added this escaped line (and similar for other jshint settings) to the top of your file.

// jshint esversion:6

Actually you can add it anywhere, but it only effects subsequent code, allowing you to flip settings on and off if you're desperate to do something weird.

answered Dec 30, 2018 at 21:40

Comments

3

Add the next hint before your code:

/* jshint esversion: 6 */

Example

answered Feb 10, 2021 at 14:03

1 Comment

simplest to do in a mixed development environment
0

Make sure, you do the above configurations with the json but also remove/disable the jshint extension for workspace if you're using eslint and vice versa.,

answered Nov 26, 2019 at 7:45

Comments

-1

Disable your jshint extension like this:

https://i.sstatic.net/mYnM2.png

Gino Mempin
30.5k31 gold badges125 silver badges174 bronze badges
answered Mar 1, 2020 at 0:43

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.