本文介绍了eslint:错误解析错误:关键字'const'被保留的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从 ESLint 收到此错误:
I am getting this error from ESLint:
error Parsing error: The keyword 'const' is reserved
来自此代码:
const express = require('express');
const app = express();
const _ = require('underscore');
我尝试删除 node_modules
并重新安装所有 npm 包(如建议的 此处),但无济于事.
I've tried removing node_modules
and reinstalling all npm packages (as suggested here), but to no avail.
推荐答案
ESLint 默认使用 ES5 语法检查.您需要覆盖到最新的受良好支持的 JavaScript 版本.
ESLint defaults to ES5 syntax-checking. You'll want to override to the latest well-supported version of JavaScript.
尝试将 .eslintrc
文件添加到您的项目中.里面:
Try adding a .eslintrc
file to your project. Inside it:
{
"parserOptions": {
"ecmaVersion": 2017
},
"env": {
"es6": true
}
}
希望这会有所帮助.
我还发现了 这个示例 .eslintrc
帮助.
I also found this example .eslintrc
which might help.
这篇关于eslint:错误解析错误:关键字'const'被保留的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!