我有一个index.js文件,其中包含以下命名导出。
export Main from './Main/Main'
但是,eslint不喜欢这个并抛出错误
Parsing error: Unexpected token Main
我不确定为什么应用程序正常运行,我相信这是有效的语法。
我的.eslintrc文件看起来像这样
{
env: {
es6: true,
browser: true
},
parserOptions: {
ecmaVersion: 6,
sourceType: "module",
ecmaFeatures: {
jsx: true,
experimentalObjectRestSpread: true
}
},
plugins: [
"react",
],
extends: ["eslint:recommended", "plugin:react/recommended", "standard"],
"rules": {
"comma-dangle" : [2, "always-multiline"],
"semi": [2, "never"],
"no-extra-semi": 2,
"jsx-quotes": [2, "prefer-single"],
"react/jsx-boolean-value": [2, "always"],
"react/jsx-closing-bracket-location": [2, {selfClosing: "after-props", nonEmpty: "after-props"}],
"react/jsx-curly-spacing": [2, "never", {"allowMultiline": false}],
"react/jsx-max-props-per-line": [2, {maximum: 3}],
"react/jsx-no-literals": 2,
"react/sort-prop-types": 2,
"react/self-closing-comp": 2,
"react/sort-comp": 2
},
}
答案 0 :(得分:11)
想出来。这是一个实验性功能,所以我需要启用babel-eslint作为我的eslint解析器。
现在我的.eslintrc看起来像这样
{
parser: "babel-eslint",
env: {
es6: true,
browser: true
},
parserOptions: {
ecmaVersion: 6,
sourceType: "module",
ecmaFeatures: {
jsx: true,
experimentalObjectRestSpread: true
}
},
plugins: [
"react",
],
extends: ["eslint:recommended", "plugin:react/recommended", "standard"],
"rules": {
"comma-dangle" : [2, "always-multiline"],
"semi": [2, "never"],
"no-extra-semi": 2,
"jsx-quotes": [2, "prefer-single"],
"react/jsx-boolean-value": [2, "always"],
"react/jsx-closing-bracket-location": [2, {selfClosing: "after-props", nonEmpty: "after-props"}],
"react/jsx-curly-spacing": [2, "never", {"allowMultiline": false}],
"react/jsx-max-props-per-line": [2, {maximum: 3}],
"react/jsx-no-literals": 2,
"react/sort-prop-types": 2,
"react/self-closing-comp": 2,
"react/sort-comp": 2
},
}
答案 1 :(得分:0)
因为我因为不同的原因得到了同样的错误,所以这就是我出错的地方:
如果你正在使用带有原子包开发的babel,那么babel会在每个文件的开头由use babel
激活。
use babel
,就像use strict
一样,需要在文件的最开头!就像它前面的空间将停用它一样,然后js引擎绊倒你的导出语句,或类似的```意外的令牌导出````。
错:
use babel
import { bla } from 'blub'
正确:
use babel
import { bla } from 'blub'