简体   繁体   English

eslint 解析错误: ecmaVersion must be 3, 5, 6, or 7

[英]eslint Parsing error: ecmaVersion must be 3, 5, 6, or 7

I'm using the eslint 3.18.0 and node 7.7.4.我正在使用 eslint 3.18.0 和节点 7.7.4。 I'm setting the ecmaVersion to 8 ( per the documentation ), but getting this error: Parsing error: ecmaVersion must be 3, 5, 6, or 7. Is ecmaVersion 8 not supported?我将 ecmaVersion 设置为 8(根据文档),但收到此错误:解析错误:ecmaVersion 必须为 3、5、6 或 7。是否不支持 ecmaVersion 8? If it is why am I getting this parsing error?如果这是为什么我会收到这个解析错误?

Here's the full .eslintrc.json:这是完整的 .eslintrc.json:

{
    "env": {
        "node": true,
        "mocha": true
    },
    "parserOptions": {
        "ecmaVersion": 8,
        "sourceType": "module"
    },
    "extends": "eslint:recommended",
    "rules": {
        "semi": ["error", "always"],
        "quotes": ["error", "single"]
    }
}

ESLint currently supports versions 3, 5, 6 (es2015), 7(es2016) and 8(es2017). ESLint 目前支持版本 3、5、6 (es2015)、7(es2016) 和 8(es2017)。 If you are having trouble enabling es2017, verify that your ESLint installation is up to date.如果您在启用 es2017 时遇到问题,请确认您的 ESLint 安装是最新的。 es2017 was added to ESLint as of v3.6.0 that was released on Sep 23, 2016. Verify global/local version (whichever you are using). es2017 从 2016 年 9 月 23 日发布的 v3.6.0 开始添加到 ESLint。验证全局/本地版本(无论您使用的是哪个)。

I solved this by doing the following我通过执行以下操作解决了这个问题

  1. Deleted the node-modules directory & package-lock.json删除了 node-modules 目录和 package-lock.json
  2. npm install安装
  3. Changed the ecmaScript version in .eslint file更改了 .eslint 文件中的 ecmaScript 版本

It worked for me.它对我有用。

The ecmaVersion is not valid; ecmaVersion 无效; I recently installed eslint and ecamVersion was set to 13我最近安装了 eslint 并且 ecamVersion 设置为 13

"parserOptions": { "ecmaVersion": 13 }, "parserOptions": { "ecmaVersion": 13 },

The valid versions are 3 to 12 or latest.有效版本为 3 到 12 或最新。 I use 'latest' :)我使用“最新”:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM