我正在尝试开始使用 Typescript 进行 Electron 开发。在努力输入节点和 jquery 之后,我终于得到了我的 .ts 文件无错误。
现在的问题是,当我运行我的应用程序时,我收到了这个错误:
index.js:2 Uncaught ReferenceError: exports is not defined
这些是 index.js 中的前两行:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
我不知道那条线会。 Typescript 在编译时添加了它。如果我删除它,我的应用程序可以正常工作。
我该如何摆脱这个错误?
哦,这是我的 tsconfig,如果相关的话。
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"isolatedModules": false,
"jsx": "react",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": false,
"noImplicitAny": false,
"noImplicitUseStrict": false,
"removeComments": true,
"noLib": false,
"preserveConstEnums": true,
"suppressImplicitAnyIndexErrors": true
},
"exclude": [
"node_modules",
"typings/browser",
"typings/browser.d.ts"
],
"compileOnSave": true,
"buildOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
原文由 Blargmode 发布,翻译遵循 CC BY-SA 4.0 许可协议
新版本的 typescript 2.2.1 存在问题,请尝试使用旧版本 2.1.6,它解决了您遇到的完全相同的问题。
编译时的 2.2.1 版本添加了这一行
Object.defineProperty(exports, "__esModule", { value: true });
而旧的 2.1.6 没有。