【发布时间】:2020-01-22 16:56:36
【问题描述】:
在我最近设置的一个 Typescript 项目中,我让 Babel 来编译我的 Typescript 代码。我还使用 @typescript-eslint 作为我的 linter。到目前为止,它一直运行良好,直到最近我尝试在我的代码中使用 Symbol。
出于某种原因,Typescript(或 Babel)无法识别 Symbol 并给我一个错误 Symbol is not defined。
这是我的 eslintrc 的外观:
{
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint/eslint-plugin"
]
}
在我的 babelrc 中,我有以下内容:
{
"presets": [
[
"@babel/preset-env"
],
["@babel/preset-typescript"]
],
"plugins": [
"@babel/plugin-transform-modules-commonjs",
[
"@babel/plugin-transform-runtime",
{
"corejs": 2
}
]
]
}
为什么会发生这种情况,我该如何解决这个问题?
【问题讨论】:
-
你也可以添加你的配置堆栈,尤其是 eslint 和 babel。因为你的帖子缺少很多
-
@StefanoMtangoo 当然,我已经添加了有关我的 eslint 和 babel 配置的更多信息。
-
@StefanoMtangoo 是的,我有一个 .eslintrc 文件。我已将其设置为此
"ecmaVersion": 2018 -
到目前为止,我在配置中没有发现任何问题。那么除了 Symbol 之外的其他 ECMA2015 功能是否有效?
-
@StefanoMtangoo 是的,到目前为止,我没有任何问题,直到我尝试使用
Symbol。
标签: javascript typescript webpack babeljs eslint