打字稿电子出口未定义 [英] Typescript & Electron exports is not defined

查看:52
本文介绍了打字稿电子出口未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行我的简单电子应用程序。我将Typescript用作可编译为JavaScript的开发语言。当我运行应用程序时,出现以下错误:

I'm trying to run my simple electron app. I use Typescript as a development language which compiles into JavaScript. When I run the app I get the following error:

ReferenceError: exports is not defined[Learn More]
file:///Users/ahmet/Documents/JumbleUp-Desktop/dist/Login/Login.js:5
exports.__esModule = true;

我的login.ts文件看起来像这样

My login.ts file looks like this

    import firebase from "firebase";

firebase.auth().onAuthStateChanged(function(user) {
    if (user) {
        location.replace("index.html");
    } else {
        location.replace("login.html");
    }
  });
function login() {
    const userEmail = (document.getElementById("inputEmail") as HTMLInputElement).value;
    const userPassword = (document.getElementById("inputPassword") as HTMLInputElement).value;

    firebase.auth().createUserWithEmailAndPassword(userEmail, userPassword).catch(function(error) {
        // Handle Errors here.
        var errorCode = error.code;
        var errorMessage = error.message;
        // ...

        window.alert("Alert : " + errorMessage);
      });
}

,这里是我的tsconfig文件

and here my tsconfig file

{
    "compilerOptions": {
      "module": "commonjs",
      "noImplicitAny": true,
      "sourceMap": true,
      "esModuleInterop": true,
      "outDir": "dist",
      "baseUrl": ".",
      "paths": {
        "*": ["node_modules/*"]
      }
    },
    "include": [
      "src/**/*"
    ]
  } 


推荐答案

我遇到了相同的问题问题。对我来说,问题不在于文件的转译方式,而是文件在 index.html 中如何包含在项目中。

I've encountered the same problem. For me the problem was not in the way the files are transpiled, but by how they were included in the project in index.html.

更改:

<script src="./main.js"></script>

<script>
   require("./main.js")
</script>

在index.html中

in index.html

解决了它对我来说

这篇关于打字稿电子出口未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆