1

看起来从 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 ]
}
4

1 回答 1

1

错误说明了一切:

以 es6 或更高版本为目标时,无法将外部模块编译为 amd 或commonjs 。

ES6 内置了模块,因此请从以下内容中删除此行tsconfig.json

"module": "commonjs",

然后因为你是用 babel 从 ES6 编译到 ES5,告诉它编译到 CommonJS:

 babel --modules common ...etc...
于 2015-07-15T19:53:59.037 回答