'ERR_FILE_NOT_FOUND index.ff634a51.js and index.62f502b0 only after build my Electron app
Electron-Builder Version: 23.0.3
Node Version: 14.16.0
Electron Version:18.2.0
Electron Type (current, beta, nightly):current
Hi, Im new using Electron, my actual stack is Vite + React + Electron + Electron-builder When I build my app it works correctly (in local)
I don't have any type of error or issue, but when im pass that file .dmg or .deb or .exe the electron app initialise in white screen and the console shows the next issues, Before, I also had another similar error, I was missing the preload.js error and I solved it by adding the following lines:
"files": [
...
"preload.js"
],
But as you can see I also agree ./dist/**/* line in files, that's should work.
My package.json is:
{
"name": "testeb",
"author": {
"name": "test",
},
"description": "Test app vite electron react",
"private": false,
"version": "0.0.1",
"homepage": "./",
"main": "main.js",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"electron:start": "electron .",
"pack": "electron-builder --dir",
"dist": "electron-builder",
"postinstall": "electron-builder install-app-deps"
},
"dependencies": {
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"devDependencies": {
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@vitejs/plugin-react": "^1.3.0",
"vite": "^2.9.9",
"electron": "18.2.0"
},
"build": {
"appId": "test app",
"icon": ".dist/assets/favicon.17e50649.svg",
"directories": {
"output": "dist"
},
"extraFiles": [
"./dist/assets/**"
],
"files": [
"./dist/**/*",
"main.js",
"preload.js"
],
"linux": {
"target": [
"deb"
]
},
"mac": {
"target": [
{
"target": "dmg",
"arch": [
"x64"
]
}
]
},
"win": {
"target": [
"portable"
]
}
}
}
My main.js file for Electron is:
const { app, BrowserWindow } = require("electron");
const path = require("path");
const url = require("url");
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
contextIsolation: true,
preload: path.join(__dirname, "preload.js"),
},
});
win.loadFile("./dist/index.html");
win.webContents.openDevTools();
}
app.whenReady().then(() => {
createWindow();
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
and my preload.js is:
window.addEventListener("DOMContentLoaded", () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector);
if (element) element.innerText = text;
};
for (const type of ["chrome", "node", "electron"]) {
replaceText(`${type}-version`, process.versions[type]);
}
});
I hope someone can help me with my issue, regards.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
