简体   繁体   English

尝试运行 ESLint 脚本时出现“SyntaxError: Unexpected token {”

[英]"SyntaxError: Unexpected token {" when trying to run ESLint script

I'm having issues when trying to run a lint script "lint:fix": "eslint --fix --ext .js,.jsx .”我在尝试运行 lint 脚本"lint:fix": "eslint --fix --ext .js,.jsx .”时遇到问题"lint:fix": "eslint --fix --ext .js,.jsx .” npm run lint:fix

I keep getting this error prompted and it only seems to have come about since updating my eslint deps in line with the airbnb rules (I used npx install-peerdeps --dev eslint-config-airbnb )我一直收到提示这个错误,它似乎只是因为更新我的 eslint deps 符合 airbnb 规则(我使用npx install-peerdeps --dev eslint-config-airbnb

Error:错误:

/Users/ME/Projects/MYPROJECT/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:607:28)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

However, running the following works as expected: npx eslint specific/file.js —fix但是,运行以下按预期工作: npx eslint specific/file.js —fix

This is my .eslintrc file:这是我的 .eslintrc 文件:

{
    "env": {
        "browser": true,
        "es2020": true
    },
    "extends": ["plugin:react/recommended", "airbnb", "prettier", "prettier/react"],
    "parser": "babel-eslint",
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    "plugins": ["react"],
    "rules": {}
}

And these are my current eslint deps:这些是我目前的 eslint deps:

    "eslint": "7.10.0",
    "eslint-config-airbnb": "18.2.0",
    "eslint-config-prettier": "^2.9.0",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-jsx-a11y": "6.3.1",
    "eslint-plugin-react": "7.21.3",
    "eslint-plugin-react-hooks": "4.1.2",
    "eslint-watch": "3.1.2",

Any help would be great!任何帮助都会很棒! Thanks a lot!非常感谢!

Optional catch binding was introduced in ES2019. ES2019 中引入了可选的 catch 绑定

The specified ESLint version should be used with Node version that supports it (10 or later).指定的 ESLint 版本应与支持它的Node 版本(10 或更高版本)一起使用。

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

相关问题 尝试运行量角器测试时-SyntaxError:发生意外的令牌导入 - When trying to run protractor test - SyntaxError: Unexpected token import occurs SyntaxError:运行nestjs时令牌无效或意外 - SyntaxError: Invalid or unexpected token when run nestjs 尝试运行 Node.js 应用程序时如何修复“语法错误:无效或意外令牌” - How to fix `SyntaxError: Invalid or unexpected token` when trying to run Node.js app SyntaxError:尝试使用@ babel / register时出现意外的令牌 - SyntaxError: Unexpected token export when trying to use @babel/register 尝试访问javascript对象值时出现“ SyntaxError:意外令牌,应为” - “SyntaxError: Unexpected token, expected , ” when trying to access javascript object value 意外的标记 '。' 尝试运行“npm install”时 - Unexpected token '.' when trying to run 'npm install' 无法在 ubuntu 上运行 nodemon(语法错误:意外令牌) - Not able to run nodemon (SyntaxError: Unexpected token) on ubuntu “npm run build”失败并出现 SyntaxError:Unexpected token - "npm run build" fails with SyntaxError:Unexpected token 解析错误:使用eslint时出现意外的令牌.. - Parsing error: Unexpected token .. when using eslint SyntaxError:编译 ejs 时出现意外标记 - SyntaxError: Unexpected token when compiling ejs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM