简体   繁体   English

Electron - Typescript - 找不到模块

[英]Electron - Typescript - Cannot find module

Trying to build my electron app with typescript generated from the electron-quick-start-typescript project.尝试使用从电子快速启动打字稿项目生成的 typescript 构建我的 electron 应用程序。 I have added an additional module called auth.ts which is not recognised when I start the app.我添加了一个名为 auth.ts 的附加模块,当我启动应用程序时无法识别该模块。 I am trying to reference it in renderer.ts with我试图在 renderer.ts 中引用它

import { myfunction } from './auth'

在此处输入图像描述

However I can see that it is getting converted into js.但是我可以看到它正在转换为 js。 What could be causing this issue?什么可能导致此问题? Why can't my application see my new module?为什么我的应用程序看不到我的新模块?

在此处输入图像描述

Additionally here is my package.json file if that helps.此外,如果有帮助,这里是我的 package.json 文件。

{
  "name": "electron-quick-start-typescript",
  "version": "1.0.0",
  "description": "A minimal Electron application written with Typescript",
  "scripts": {
    "build": "tsc",
    "watch": "tsc -w",
    "lint": "eslint -c .eslintrc --ext .ts ./src",
    "start": "npm run build && electron ./dist/main.js"
  },
  "repository": "https://github.com/electron/electron-quick-start-typescript",
  "keywords": [
    "Electron",
    "quick",
    "start",
    "tutorial",
    "demo",
    "typescript"
  ],
  "author": "GitHub",
  "license": "CC0-1.0",
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^4.33.0",
    "@typescript-eslint/parser": "^4.33.0",
    "electron": "^16.0.2",
    "eslint": "^7.32.0",
    "typescript": "^4.5.2"
  },
  "dependencies": {
    "node-fetch": "^2.6.1"
  }
}

Found the answer.找到了答案。 For anyone else having the same issue this resolved the issue -对于其他有同样问题的人,这解决了这个问题 -

Make sure nodeIntegration is enabled in main.js确保在 main.js 中启用了 nodeIntegration

webPreferences: {
      nodeIntegration: true,
      preload: path.join(__dirname, "preload.js"),
    },

Index.html索引.html

replace:代替:

<script src="./dist/renderer.js"></script>

with:和:

<script>
    require("./dist/renderer.js");
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM