I use electron-vite command pnpm create @quick-start/electron
init a project
and then i create a js filegetAuthKey.js
in src/main/
next to index.js
last i require getAuthKey.js
in src/main/index.js
,like this:
import { app, BrowserWindow, ipcMain, shell } from "electron";
import { join } from "path";
import { electronApp, is, optimizer } from "@electron-toolkit/utils";
import icon from '../../resources/icon.png?asset'
const getAuthKey = require("./getAuthKey"); <--------------here
const { execSync } = require("child_process");
const iconv = require("iconv-lite");
App threw an error during load
Error: Cannot find module './getAuthKey.js'
{
"name": "xxx",
"version": "1.0.0",
"description": "An Electron application with Vue",
"main": "./out/main/index.js", <----------------here
}
const getAuthKey = require("../../src/main/getAuthKey");
out/main/index.js
not pre-compilation.src/main/index.js
,what should i do?i want to require my js file to src
directory not out
directory
export function getAuthKey() {}
import { getAuthKey } from './getAuthKey'
not like this
module.exports = { getAuthKey };
const {getAuthKey} = require('./getAuthKey');