Javascript Typescript AMD目标解析为CommonJS

Javascript Typescript AMD目标解析为CommonJS,javascript,typescript,amd,Javascript,Typescript,Amd,我的项目中有一个tsconfig,它指定了一个模块目标'amd',但是当我的文件编译时,我得到的输出看起来更像CommonJS。例如: tsconfig: { "compilerOptions": { "module": "amd", "target": "es5", "moduleResolution": "node", "sourceMap": false, "newLine": "LF",

我的项目中有一个tsconfig,它指定了一个模块目标'amd',但是当我的文件编译时,我得到的输出看起来更像CommonJS。例如:

tsconfig:

{
    "compilerOptions": {
        "module": "amd",
        "target": "es5",
        "moduleResolution": "node",
        "sourceMap": false,
        "newLine": "LF",
        "baseUrl": ".",
        "lib": ["es5", "es2015.promise", "dom"]
    }
}
类型脚本文件:

export function test() {
    console.log('Starting Up', '<--------------');
}
编译文件:

define(["require", "exports"], function (require, exports) {
    Object.defineProperty(exports, "__esModule", { value: true });
    function test() {
        console.log('Starting Up', '<--------------');
    }
    exports.test = test;
});
define([], function () {
    function test() {
        console.log('Starting Up', '<--------------');
    }
    return { test: test };
});
所需的已编译文件:

define(["require", "exports"], function (require, exports) {
    Object.defineProperty(exports, "__esModule", { value: true });
    function test() {
        console.log('Starting Up', '<--------------');
    }
    exports.test = test;
});
define([], function () {
    function test() {
        console.log('Starting Up', '<--------------');
    }
    return { test: test };
});

是那个“出口”的东西把我甩了。对于AMD模块,这应该不是必需的,只是一个返回语句。有没有办法纠正这个问题?

不幸的是,没有。这是TypeScript的AMD输出的形状,它与AMD兼容。AMD提供了这一功能,TypeScript使用它。

好吧,这太糟糕了。我的代码运行的环境似乎覆盖了exports对象,因此每次推送代码时,我都必须进入编译文件并将export.function行更改为return语句。@jonlam这是什么环境?一些加载程序可能会这样做,如果他们检测到或假设CommonJSIt与一个名为NetSuite的ERP系统在一起。他们使用名为Rhino的java解释器来解释AMD模块。通常,exports对象是可用的,但在某些情况下,根据自定义模块的范围,它们似乎已禁用或忽略exports对象。在这种情况下,我认为我唯一的选择是使用gulp或其他东西来切换语法。@JonLamb可能会在TypeScript存储库中提交一个功能请求,以允许配置emit。当然,我的会被标记为重复,即使我先问过它;。不管怎样,另一个问题的解决方案对我也很有效。