未捕获的 ReferenceError:在 Typescript 生成的文件中未定义导出

编程入门 行业动态 更新时间:2024-10-28 12:23:46
本文介绍了未捕获的 ReferenceError:在 Typescript 生成的文件中未定义导出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-29 09:48:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1187587.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中未   定义   文件   ReferenceError   Typescript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!