eslint 在命名导出时抛出解析错误意外标记
eslint throws parsing error unexpected token on named export
我有一个 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
},
}
想通了。这是一个实验性功能,所以我需要启用 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
},
}
由于不同的原因我得到了同样的错误,这里是我出错的地方:
如果你在 atom 包开发中使用 babel,babel 由每个文件开头的 use babel
激活。
use babel
,就像 use strict
需要放在文件的最开头一样!在它前面的 space 会停用它,然后 js 引擎会绊倒您的导出语句或类似的```意外的令牌导出````。
错误:
use babel
import { bla } from 'blub'
正确:
use babel
import { bla } from 'blub'
我有一个 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
},
}
想通了。这是一个实验性功能,所以我需要启用 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
},
}
由于不同的原因我得到了同样的错误,这里是我出错的地方:
如果你在 atom 包开发中使用 babel,babel 由每个文件开头的 use babel
激活。
use babel
,就像 use strict
需要放在文件的最开头一样!在它前面的 space 会停用它,然后 js 引擎会绊倒您的导出语句或类似的```意外的令牌导出````。
错误:
use babel
import { bla } from 'blub'
正确:
use babel
import { bla } from 'blub'