From 53d4f2aa944b58dda9032767758d4c22c390f41e Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Wed, 18 Mar 2026 15:27:24 +0800 Subject: [PATCH] fix: use ESM imports instead of require in Electron main --- electron/main.mjs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/electron/main.mjs b/electron/main.mjs index 686fd07..0f03e68 100644 --- a/electron/main.mjs +++ b/electron/main.mjs @@ -1,7 +1,8 @@ import { app, BrowserWindow, ipcMain, dialog } from 'electron'; import path from 'path'; import { fileURLToPath } from 'url'; -import { createServer } from 'http'; +import http from 'http'; +import fs from 'fs'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -44,9 +45,8 @@ function getDistPath() { function loadDistServer() { const distPath = getDistPath(); - const indexPath = path.join(distPath, 'index.html'); - const server = require('http').createServer((req, res) => { + const server = http.createServer((req, res) => { let filePath = path.join(distPath, req.url === '/' ? 'index.html' : req.url); if (!filePath.startsWith(distPath)) { @@ -67,7 +67,6 @@ function loadDistServer() { '.md': 'text/markdown', }; - const fs = require('fs'); if (fs.existsSync(filePath)) { const contentType = contentTypes[ext] || 'application/octet-stream'; res.writeHead(200, { 'Content-Type': contentType });