在 1.5.0-beta(目标:ES6)上出现错误 TS1204,但是,一切正常
Getting error TS1204 on 1.5.0-beta (target: ES6), however, everything works fine
看起来从 Typescript 到 ES6 再到 ES5 的一切都被正确编译了。但是,我不断收到以下错误。我不知道是什么导致了这个错误...
error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher.
设置:
- 已安装 typescript 1.5.0-beta (npm install -g typescript@1.5.0-beta)
- tsconfig.json 文件如下所示。
- 使用了两个文件夹 src(所有 *.ts 文件)和 typings(外部库 *.d.ts 文件)。
- Atom编辑器在tsconfig.json
"files"属性中填写所有内容
- ES6 文件使用 Babel 编译成 ES5
tsconfig.json:
{
"version": "1.5.0-beta",
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"emitDecoratorMetadata": true,
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"preserveConstEnums": true,
"suppressImplicitAnyIndexErrors": true,
"sourceMap": true,
"outDir": "build"
},
"filesGlob": [
"./src/**/*.ts",
"./typings/**/*.ts",
"!./node_modules/**/*"
],
"files": [ redacted ]
}
错误说明了一切:
Cannot compile external modules into amd or commonjs when targeting es6 or higher.
ES6 内置了模块,所以从 tsconfig.json
:
中删除这一行
"module": "commonjs",
然后因为你正在使用 babel 从 ES6 编译到 ES5,所以告诉它编译到 CommonJS:
babel --modules common ...etc...
看起来从 Typescript 到 ES6 再到 ES5 的一切都被正确编译了。但是,我不断收到以下错误。我不知道是什么导致了这个错误...
error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher.
设置:
- 已安装 typescript 1.5.0-beta (npm install -g typescript@1.5.0-beta)
- tsconfig.json 文件如下所示。
- 使用了两个文件夹 src(所有 *.ts 文件)和 typings(外部库 *.d.ts 文件)。
- Atom编辑器在tsconfig.json "files"属性中填写所有内容
- ES6 文件使用 Babel 编译成 ES5
tsconfig.json:
{
"version": "1.5.0-beta",
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"emitDecoratorMetadata": true,
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"preserveConstEnums": true,
"suppressImplicitAnyIndexErrors": true,
"sourceMap": true,
"outDir": "build"
},
"filesGlob": [
"./src/**/*.ts",
"./typings/**/*.ts",
"!./node_modules/**/*"
],
"files": [ redacted ]
}
错误说明了一切:
Cannot compile external modules into amd or commonjs when targeting es6 or higher.
ES6 内置了模块,所以从 tsconfig.json
:
"module": "commonjs",
然后因为你正在使用 babel 从 ES6 编译到 ES5,所以告诉它编译到 CommonJS:
babel --modules common ...etc...