问题描述
限时送ChatGPT账号..我正在尝试开始使用 Typescript 进行 Electron 开发.在为 node 和 jquery 打字苦苦挣扎后,我终于摆脱了 .ts 文件错误.
I'm trying to get started with Typescript for Electron development. After wrestling with getting typing for node and jquery, I finally got my .ts file error free.
现在的问题是,当我运行我的应用程序时,出现此错误:
The problem is now that when I run my app, I get this error:
index.js:2 Uncaught ReferenceError: exports is not defined
这是 index.js 中的前两行:
These are the first two lines in index.js:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
我不知道那条线是这样的.打字稿在编译时添加了它.如果我删除它,我的应用就可以正常工作.
I don't know that that line does. Typescript added it when compiling. My app works fine if I remove it.
我如何摆脱这个错误?
哦,这是我的 tsconfig,如果相关的话.
Oh and here's my tsconfig, if that's relevant.
{
"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
}
}
推荐答案
新版本的 typescript 2.2.1 存在问题,请尝试使用旧版本 2.1.6,该版本解决了您遇到的完全相同的问题我.
There is an issue with the new version of typescript 2.2.1, try using the older version 2.1.6, that solved the exact same issue which you have for me.
2.2.1 版在编译时添加了这一行 Object.defineProperty(exports, "__esModule", { value: true });
而较旧的 2.1.6 没有.
Version 2.2.1 on compiling adds this line Object.defineProperty(exports, "__esModule", { value: true });
while the older 2.1.6 does not.
这篇关于未捕获的 ReferenceError:在 Typescript 生成的文件中未定义导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论