I install ESLint globally using the command npm install -g eslint
on my Mac. It was successful installing, but when I run eslint -v
this is the issue I encounter:
$ npm install -g eslint
path/to/bin/eslint -> path/to/lib/node_modules/eslint/bin/eslint.js
+ [email protected]
added 107 packages from 63 contributors in 4.823s
$ eslint -v
path/to/lib/node_modules/eslint/bin/eslint.js:93
} catch {
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
I would like to know what are the missing steps that cause this issue? I'm using Node.js v8.16.2 and NPM v6.4.1.
This error can occur for a number of reasons, but is typically caused by a typo or incorrect code. Luckily, the SyntaxError: Unexpected token error is relatively easy to fix. In most cases, the error can be resolved by checking the code for accuracy and correcting any mistakes.
The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided. This might be a simple typo.
A parse error is an error message you sometimes get on Android devices when an app fails to install. The message itself is not very specific, and there are a lot of problems that can cause it.
The error happens because } catch {
is a relatively recent (ES2019) language feature called "optional catch binding"; prior to its introduction, binding the caught error (e.g. } catch (err) {
) was required syntactically. Per node.green, you need at least Node 10 to have that language feature.
So why does this happen in ESLint? Per e.g. the release blog, version 7 has dropped support for Node 8; they're no longer testing against that version and more modern language features will be assumed to be supported.
To fix it, either:
npm install eslint@6
(with -g
if you want to install globally) to use the older version of ESLint with Node 8 support.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