You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

全局安装ESLint后运行eslint -v遇Unexpected Token错误的排查与修复

Why You're Getting This ESLint Syntax Error & How to Fix It

The Root Cause

That SyntaxError: Unexpected token { you're seeing boils down to version incompatibility between Node.js and ESLint:

  • The ESLint 7.3.1 version you installed uses an ES2019 feature called parameterless catch (catch {}), which your Node.js v8.16.2 doesn't support. Node.js didn't add support for this syntax until version 10.12.0.
  • When Node tries to run ESLint's code, it hits that unsupported catch {} line and throws the syntax error immediately.

Fixes (Pick One That Fits Your Needs)

Option 1: Downgrade ESLint to a Node 8-Compatible Version

ESLint 6.x is the last major release that supports Node.js 8. Install the latest 6.x version globally with this command:

npm install -g eslint@6

Once installation finishes, running eslint -v should display the version number correctly instead of throwing an error.

Option 2: Upgrade Your Node.js Version

If your projects allow for it, upgrading Node.js to v10.12.0 or higher (preferably an LTS release like v14.x or v16.x) is the better long-term solution. It will resolve the ESLint compatibility issue and also give you access to newer Node.js features, performance improvements, and security updates.

If you use nvm (Node Version Manager) to manage multiple Node versions, here's how to switch:

# Install the latest v16 LTS release
nvm install 16
# Switch to the newly installed version
nvm use 16

After upgrading, reinstall ESLint globally and it should work perfectly.


内容的提问来源于stack exchange,提问作者user3818576

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 10:58:15