My javascript:
let foo = 'bar'
Why does ESLint respond with the following?
~/index.js
1:5 error Parsing error: Unexpected token foo
✖ 1 problem (1 error, 0 warnings)
It seems like no matter where in the script, the first instance of using let to set a variable gets this error. Why??
My .eslintrc file:
module.exports = {
"env": {
"node": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"never"
]
}
};
The answers about let
being forbidden in the global scope are wrong. That's fine.
The problem is that you need to let eslint know you're using es6 features.
Do that by adding an "es6": true
line to the env
block in your config:
.eslintrc.js
module.exports = {
"env": {
"node": true,
"es6": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"never"
]
}
};
That fixes your particular error, but you'll soon see errors about unused names. Below is the minimum source code I could find that will pass your eslint settings:
let.js
let foo = 'bar'
function main() {
foo
}
main()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With