-
I use electron-vite command
pnpm create @quick-start/electron
init a project -
and then i create a js file
getAuthKey.js
insrc/main/
next toindex.js
-
last i require
getAuthKey.js
insrc/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");
- then i get error
App threw an error during load
Error: Cannot find module './getAuthKey.js'
- check the package.json and i find the problem
{
"name": "xxx",
"version": "1.0.0",
"description": "An Electron application with Vue",
"main": "./out/main/index.js", <----------------here
}
- then i change code to
const getAuthKey = require("../../src/main/getAuthKey");
- ok, code run ,i know require is to
out/main/index.js
not pre-compilation. - but i want to require my js file to
src/main/index.js
,what should i do?
i want to require my js file to src
directory not out
directory
New contributor
little weilai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.