Im building an Electron App with Vite that uses Axios. It seems that Axios requires a dynamically imported package called form-data. When running my built .exe portable after Ive built it I get the following error:
I have attempted to manually insert the import the package into various places in my app, including importing it into my dependencies:
... existing code ...
"dependencies": {
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0",
"@mui/icons-material": "^6.4.7",
"@mui/material": "^6.4.7",
"@tanstack/react-query": "^5.67.3",
"axios": "^1.8.3",
"classnames": "^2.5.1",
"date-fns": "^4.1.0",
"form-data": "^4.0.2",
"fuzzysort": "^3.1.0",
"lodash.debounce": "^4.0.8",
"material-symbols": "^0.29.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-router-dom": "^7.3.0",
"uuid": "^11.1.0"
},
... existing code ...
Ive put it in my electronBuilder:
{
"appId": "com.jsarrakis.prism",
"files": ["dist-electron", "dist-react", "node_modules/form-data/**/*"],
"extraResources": ["dist-electron/preload.cjs"],
"icon": "./desktopIcon.png",
"mac": {
"target": "dmg"
},
"linux": {
"target": "AppImage",
"category": "Utility"
},
"win": {
"target": ["portable"]
}
}
Ive added it to my Vite config:
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
base: "./",
build: {
outDir: "dist-react",
rollupOptions: {
external: ["form-data"],
},
},
server: {
port: 5123,
strictPort: true,
},
});
And Ive even tried to force an import into my main.ts:
import { app, BrowserWindow, Menu } from "electron";
import "form-data";
import { ipcMainHandle, isDev } from "./util.js";
import { getPreloadPath, getUIPath } from "./pathResolver.js";
import { openFileDialogHandler } from "./handlers/commonHanlders.js";
... existing imports ...
app.on("ready", () => {
... existing code ...
I still cant seem to get it to work. When running in development outside of the exe however, the app runs fine and axios and the rest of the app perform as expected.
Im wondering what I might be missing or if I just need to drop axios and go for something like node-fetch or got.
