Skip to content

Using the official electron forge template, when running the npm run package file and opening the generated exe file, the page cannot be displayed. This issue can occur with versions above 20.0.0. #3217

Open
@whw155

Description

@whw155

Pre-flight checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project uses.
  • I have searched the issue tracker for a bug that matches the one I want to file, without success.

Electron Forge version

6.1.1

Electron version

22.3.5

Operating system

window11,AMD的CPU

Last known working Electron Forge version

No response

Expected behavior

Using a version of 20.0.0 or higher, using the electronic forge official template, open the generated exe file after running the npm run package, and it can be used in any environment.

Actual behavior

Using the official electron forge template, when running the npm run package file and opening the generated exe file, the page cannot be displayed. This issue can occur with versions above 20.0.0.

After testing, it was found that this issue only occurred in the Windows version, under the CPU of AMD. In the Windows Intel CPU environment, there is no such issue, however. The package used normally in Intel environment cannot be used in AMD environment.

By outputting logs, it was found that during the main process rendering, browserWindow. webContent. loadFlie() threw an error when loading the file.

[Sun Apr 16 2023 10:38:24 GMT+0800 ] loadFlie---reject--event---Error: ERR_FAILED (-2) loading 'file://D:\work_code\study\electron\my-app1\out\my-app1-win32-x64\resources\app.webpack\renderer\main_window\index.html'
[Sun Apr 16 2023 10:38:24 GMT+0800 ] loadFlie---reject--event---{"errno":-2,"code":"ERR_FAILED","url":"file://D:\work_code\study\electron\my-app1\out\my-app1-win32-x64\resources\app.webpack\renderer\main_window\index.html"}

Steps to reproduce

project init

npm init electron-app@latest my-new-app -- --template=webpack

package.json

{ "name": "my-app1", "productName": "my-app1", "version": "1.0.0", "description": "My Electron application description", "main": ".webpack/main", "scripts": { "start": "electron-forge start", "package": "electron-forge package", "make": "electron-forge make", "publish": "electron-forge publish", "lint": "echo \"No linting configured\"" }, "keywords": [], "author": { "name": "whw", "email": "[email protected]" }, "license": "MIT", "devDependencies": { "@electron-forge/cli": "^6.1.1", "@electron-forge/maker-deb": "^6.1.1", "@electron-forge/maker-rpm": "^6.1.1", "@electron-forge/maker-squirrel": "^6.1.1", "@electron-forge/maker-zip": "^6.1.1", "@electron-forge/plugin-webpack": "^6.1.1", "@vercel/webpack-asset-relocator-loader": "1.7.3", "css-loader": "^6.0.0", "node-loader": "^2.0.0", "style-loader": "^3.0.0", "electron": "~22.3.5" }, "dependencies": { "electron-squirrel-startup": "^1.0.0" } }

main.js

`
const { app, BrowserWindow } = require('electron');
const path = require('path');

const fs = require('fs');
const url = require('url');
// 获取日志文件路径
const logFilePath = path.join(__dirname, 'logs', 'app.log');

// 创建日志文件夹(如果不存在)
if (!fs.existsSync(path.dirname(logFilePath))) {
fs.mkdirSync(path.dirname(logFilePath));
}
console.log(logFilePath);
// 写入日志信息到文件中
function setLog(log) {
fs.appendFileSync(logFilePath, [${new Date().toString()}] ${log}\n);
}
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) {
app.quit();
}

const createWindow = () => {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY
}
});

// and load the index.html of the app.
mainWindow
.loadURL(MAIN_WINDOW_WEBPACK_ENTRY)
.then((res) => {
setLog(loadFile----resolve----${res});
})
.catch((event, errorCode, errorDescription, validatedURL, isMainFrame, frameProcessId, frameRoutingId) => {
setLog(loadFlie---reject--event---${event});
setLog(loadFlie---reject--event---${JSON.stringify(event)});
setLog(loadFlie---reject--errorCode---${errorCode});
setLog(loadFlie---reject--errorDescription---${errorDescription});
setLog(loadFlie---reject--validatedURL---${validatedURL});
setLog(loadFlie---reject--isMainFrame---${isMainFrame});
setLog(loadFlie---reject--frameProcessId---${frameProcessId});
setLog(loadFlie---reject--frameRoutingId---${frameRoutingId});
});

// Open the DevTools.
mainWindow.webContents.openDevTools();
};

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});

app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and import them here.

`

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocked/needs-reproIssues unable to be reproduced by maintainersbug

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions