使用ESLint lint fix时遇`splitter ??= new graphemer_1.default();`错误求助
解决方案
你遇到的错误是因为ESLint未识别??=(空值合并赋值运算符)语法,该语法属于ES2020标准,需确保ESLint配置正确支持对应ECMAScript版本。以下是具体修复步骤:
检查
.eslintrc.json的parserOptions配置,将ecmaVersion设为2020或更高:{ "parserOptions": { "ecmaVersion": 2020, "sourceType": "module" } }若为TypeScript项目,确认使用
@typescript-eslint/parser作为解析器,并完善配置:{ "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": 2020, "sourceType": "module", "project": "./tsconfig.json" } }更新ESLint及相关依赖到最新稳定版,确保版本兼容性:
npm update eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin检查
tsconfig.json的target字段,至少设置为ES2020以支持该语法编译:{ "compilerOptions": { "target": "ES2020" } }
调整完成后重新运行npm run lint或npm run lint:fix,再尝试Git提交即可。
内容的提问来源于stack exchange,提问作者Purvi Vichhi
相关产品推荐
相关产品推荐

