WebStorm 为 `commonjs` 模块添加了`Object.defineProperty(exports, "__esModule", { value: true });`
WebStorm adds `Object.defineProperty(exports, "__esModule", { value: true });` for `commonjs` modules
使用 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 添加这一行?
您必须为 tsc 使用不同的打字稿版本。从 2.2 开始,所有 ES6 模块都会发出 __esModule
。参见 https://github.com/Microsoft/TypeScript/issues/13709
使用 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 添加这一行?
您必须为 tsc 使用不同的打字稿版本。从 2.2 开始,所有 ES6 模块都会发出 __esModule
。参见 https://github.com/Microsoft/TypeScript/issues/13709