如何告诉eslint允许分阶段ECMA-Script动态导入 [英] How to tell eslint to allow staged ECMA-Script dynamic imports
问题描述
我想使用现在的阶段3"提案import()
.如果我用ESLint整理我的代码,那就是在抱怨:
I want to use the now "Stage-3" proposal import()
. If I lint my code with ESLint it's complaining about:
Parsing error: 'import' and 'export' may only appear at the top level
对于import
的静态形式正确,但对于新的动态形式却不正确.我找不到使ESLint允许的正确选项.有人可以给我提示吗?
Which is correct for the static form of import
but not for the new, dynamic one. I don't find the right option to make ESLint allow that. Can someone give me a hint?
推荐答案
当然是Gyandeep的权利.这不是规则的问题,而是解析器的问题(毕竟这就是解析错误的意思……).因此,我现在将babel-eslint
与以下.eslintrc
(摘录)一起使用:
Of course is Gyandeep right. It's no question of rules but of the parser (That's what parsing error means after all…). So I use now babel-eslint
with the following .eslintrc
(excerpt):
{
"parser": "babel-eslint",
"parserOptions": {
"allowImportExportEverywhere": true
}
}
此外,我确保我已安装并使用 babel-plugin-syntax-dynamic-import
Also, I made sure I installed and used babel-plugin-syntax-dynamic-import
.
这篇关于如何告诉eslint允许分阶段ECMA-Script动态导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!