我正在尝试为我的Express应用程序添加一个linter,并且我收到了几个关于ES6的linter错误,即‘export’ is only available in ES6 (use esnext option)
,’const’ is only available in JavaScript 1.7
和’arrow function syntax’ is only available in Javascript 1.7
。我不知道如何摆脱这些错误 - 任何帮助将不胜感激。我目前已经尝试过安装一些东西,包括Sublime Text 2 linter和babel-eslint,但可能接近这个错误。
来自相关的package.json:
{
"dependencies": {
"babel-cli": "^6.10.1",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-2": "^6.5.0",
"bcrypt-nodejs": "0.0.3",
"botkit-sms": "^1.1.0",
"dotenv": "^2.0.0",
"express": "^4.14.0",
"jwt-simple": "^0.5.0",
"mongoose": "^4.6.3",
"passport": "^0.3.2",
"passport-jwt": "^2.2.1",
"passport-local": "^1.0.0",
"request": "^2.76.0",
"routific": "0.0.2"
},
"devDependencies": {
"babel-eslint": "^6.1.2",
"eslint": "^2.13.1",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-import": "^1.16.0",
"eslint-plugin-jsx-a11y": "^1.4.2",
"eslint-plugin-react": "^5.1.1",
"nodemon": "^1.9.2"
}
}
.babelrc:
{
"presets": ["es2015", "stage-2"]
}
.eslintrc:
{
extends: ["airbnb", "esnext"],
parser: "babel-eslint",
env: {
browser: false,
node: true,
es6: true
},
rules: {
strict: 0,
quotes: [2, "single"],
no-else-return: 0,
new-cap: ["error", {"capIsNewExceptions": ["Router"]}],
no-console: 0,
import/no-unresolved: [2, { commonjs: true}],
no-unused-vars: ["error", { "vars": "all", "args": "none" }],
no-underscore-dangle: 0,
arrow-body-style: ["error", "always"],
no-shadow: ["error", { "allow": ["done", "res", "cb", "err", "resolve", "reject"] }],
no-use-before-define: ["error", { "functions": false }],
max-len: 0
},
plugins: [
'import'
],
ecmaFeatures: {
jsx: true,
modules: true
}
}
答案 0 :(得分:2)
在首选项中将esnext设置为true - >包装设置 - > Sublimelinter - >设置 - 用户为我工作
{
"jshint_options":
{
"esnext": true
}
}
答案 1 :(得分:0)
我认为你必须摆脱esnext 这是我的节点.eslintrc:
{
"extends" : "airbnb",
"rules": {
// disable requiring trailing commas because it might be nice to revert to
// being JSON at some point, and I don t want to make big changes now.
"comma-dangle": 0,
// we can use escape and template strings
"quotes": [1, "single", {"avoidEscape": true, "allowTemplateLiterals": true}],
"max-len": [0],
"no-console": 0,
"no-param-reassign": 0
},
"globals": { "ENV": true },
"env": {
"browser": true,
"node": true,
"jasmine": true
}
}
这些是我的devDependencies
"devDependencies": {
"babel-cli": "^6.9.0",
"babel-core": "^6.9.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-0": "^6.5.0",
"eslint": "^3.1.1",
"eslint-config-airbnb": "^12.0.0",
"eslint-plugin-import": "1.16.0",
"eslint-plugin-jsx-a11y": "2.2.3",
"eslint-plugin-react": "6.4.1",
"nodemon": "^1.9.2"
}
答案 2 :(得分:0)
ecmaFeatures
配置设置在parserOptions
下。
...
plugins: [
'import'
],
parserOptions: {
ecmaFeatures: {
jsx: true
},
ecmaVersion: 6,
sourceType: 'module'
},
...
您应该使用sourceType: 'module'
代替modules: true
。