WebStorm添加`Object.defineProperty(exports,“__ myModule”,{value:true});`for`commonjs` modules

时间:2017-06-14 16:34:26

标签: typescript webstorm jetbrains-ide

使用TypeScript服务时,WebStorm会将以下内容添加到输出中:

Object.defineProperty(exports, "__esModule", { value: true });

可以在以下输出中看到:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true }); <----------
var rabbit_1 = require("./rabbit");
var r = new rabbit_1.Rabbit();
r.go();

tsconfig.json配置如下

{
    "compilerOptions": {
        "module": "commonjs",  <---------------
        "target": "es5",
        "noImplicitAny": false,
        "sourceMap": false
    }
}

tsc正确输出commonjs中的模块。为什么WebStorm会添加这一行?

1 个答案:

答案 0 :(得分:2)

您必须为tsc使用不同的打字稿版本。从2.2开始,所有ES6模块都会发出__esModule。见enter image description here

相关问题