Typescript AMD Target Resolving to CommonJS [duplicate]

我与影子孤独终老i 提交于 2019-12-13 00:13:26

问题


I have a tsconfig in my project that specifies a module target of 'amd' but when my file compiles I am getting an output that looks more like CommonJS. Example:

tsconfig:

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

Typescript File:

export function test() {
    console.log('Starting Up', '<--------------');
}

Compiled File:

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

Expected Compiled File:

define([], function () {
    function test() {
        console.log('Starting Up', '<--------------');
    }
    return { test: test };
});

It's the 'export' object that's throwing me off. This should not be necessary for an AMD module, only a return statement. Is there a way to correct this?


回答1:


Unfortunately not. That is the shape of TypeScript's AMD output and it is AMD compliant. AMD offers this facility and TypeScript uses it.



来源:https://stackoverflow.com/questions/46894234/typescript-amd-target-resolving-to-commonjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!