--out 仅支持 'amd' 和 'system' 模块

Only 'amd' and 'system' modules are supported alongside --out

在 VSCode 中构建打字稿时,出现以下错误:

error TS6082: Only 'amd' and 'system' modules are supported alongside --out.

我的设置如下:

tsconfig.json

{
    "compilerOptions": {
        "target": "ES5",
        "module": "commonjs",
        "out": "current/game.js",
        "removeComments": true,
        "sourceMap": false
    }
}

.vscode/tasks.json:

{
    "version": "0.1.0",

    // The command is tsc. Assumes that tsc has been installed using npm install -g typescript
    "command": "tsc",

    // The command is a shell script
    "isShellCommand": true,

    // Show the output window only if unrecognized errors occur.
    "showOutput": "silent",

    // args is the HelloWorld program to compile.
    "args": [],

    // use the standard tsc problem matcher to find compile problems
    // in the output.
    "problemMatcher": "$tsc"
}

尽管有错误,game.js 文件确实创建并正常运行。

有人对可能导致此错误的原因有任何想法吗?

言出必行。您不能使用 --out/--outFile 将 Node.js/CommonJS 的模块捆绑在一起,因为 CommonJS 没有捆绑格式。简单地不要为 CommonJS 使用该选项,并且将为每个输入 TS 模块文件发出相应的 JS 文件。