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

VSCode ESLint插件报‘Unexpected Token’错误的原因咨询

ESLint报「Parsing error: Unexpected token func1」的原因解析

问题背景

环境与配置

  • 开发工具:VSCode + ESLint扩展
  • Node.js版本:16
  • ESLint配置:
{
    "env": {
        "node": true,
        "commonjs": true,
        "es2021": true
    },
    "extends": "eslint:recommended",
    "overrides": [],
    "parserOptions": {
        "ecmaVersion": "latest"
    },
    "rules": {
        "no-unused-vars": "off"
    }
}

待检测代码

async function func1 (val) {
  console.log(val);
}

await func1("blah");

报错信息

Parsing error: Unexpected token func1

错误原因

  1. await的使用场景限制:await关键字只能在async函数内部,或者ES模块(ESM)的顶层作用域中使用。
  2. 当前代码被识别为CommonJS模块:你的ESLint配置里env.commonjs设为true,说明代码以CommonJS模式运行。而Node.js 16的CommonJS模块不支持顶层await,直接在全局作用域写await func1("blah")违反了语法规则,导致ESLint解析失败。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 05:05:18