Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode and ES6 warnings

I keep on getting ES6 jshint warnings, for example: ''import' is only available in ES6 (use 'esversion: 6'). (W119)' source: 'jshint' code: 'W119'

I followed suggestions such as

  1. Adding a .jshintrc file in the root with { "esversion": 6 }
  2. Adding the following to the user and\or workspace settings: "jshint.options":{ "esversion":6 }

But I still get the warning. Are there other things that I can do?

Thanks

like image 291
user1786037 Avatar asked Mar 15 '18 13:03

user1786037


3 Answers

jsHint's ES6 warning can be solved easily by the following JSON code without creating any new file: Paste the code inside the JSON editor of the "user settings".

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

like image 126
Bandhan Avatar answered Oct 16 '22 11:10

Bandhan


jsconfig.json file which defines the JavaScript target to be ES6

I create a jsconfig.json file under my project directory and add codes in it:

{
    "compilerOptions": {
        "target": "ES6"
},
    "exclude": [
        "node_modules",
        "**/node_modules/*"
    ]
}
like image 31
Calvin Avatar answered Oct 16 '22 12:10

Calvin


According to the JSHint documentation: https://jshint.com/docs/ "In addition to using configuration files you can configure JSHint from within your files using special comments. These comments start with a label such as jshint or globals..."

So, a /* jshint esversion: 6 */ comment will work on the top of each file targeting ES6. This have the advantage of you can switch these directives on and off per file or per function: "These comments are function scoped meaning that if you put them inside a function they will affect only this function's code."

like image 1
Hairy H. Avatar answered Oct 16 '22 11:10

Hairy H.