【发布时间】:2020-05-08 14:54:21
【问题描述】:
我有这个 tsconfig
{
"compilerOptions": {
"target": "es6",
"lib": ["es6"],
"outFile": "index.js"
}
}
当我编译创建类时出现错误: 使用esversion:es6
我在哪里添加这一行?真的在 tsconfig 中吗?
【问题讨论】:
标签: typescript visual-studio-code
我有这个 tsconfig
{
"compilerOptions": {
"target": "es6",
"lib": ["es6"],
"outFile": "index.js"
}
}
当我编译创建类时出现错误: 使用esversion:es6
我在哪里添加这一行?真的在 tsconfig 中吗?
【问题讨论】:
标签: typescript visual-studio-code
您使用 ES6 模块编写 TS 源代码,但截至 2016 年 1 月,没有浏览器原生支持此模块系统。因此,您可能希望将 ES6 模块转换为不同的模块系统:CommonJS、AMD、SystemJS。这可以使用模块选项来完成。有构建时或运行时转译器将 ES6 模块系统转译成构建系统 (Webpack) 或模块加载器 (SystemJS) 支持的模块系统之一。如果未指定,则如果目标是 ES6,则模块默认为 ES6,否则为 CommonJS。我更喜欢明确地将目标设置为 CommonJS:
也许你应该添加module 属性。
{
"compilerOptions": {
"module": "CommonJS" // for exapmle
}
}
另外你应该添加lib:
{
"compilerOptions": {
"lib": ["es6", "dom"],
}
}
【讨论】: