gpt4 book ai didi

javascript - 在 Windows 10 上尝试使用 CMD 将 Electron 项目编译为 .exe 时,Electron-packager 返回 "Response code 404 (Not Found)"

转载 作者:太空宇宙 更新时间:2023-11-04 01:17:28 24 4
gpt4 key购买 nike

我是一名初学者开发人员,刚刚熟悉 Electron 和 Node.js。我正在尝试使用 Electron 打包程序包将我的 Electron 项目转换为 .exe 文件,但每次尝试时都会返回此错误:

Response code 404 (Not Found) for https://github.com/electron/electron/releases/download/v0.35.6/SHASUMS256.txt

我已经尝试过该 URL,它返回错误 404,显然,“releases”以下的任何内容都不存在。我正在使用 Windows 10(如果有帮助的话)。

这是我的 main.js 文件:

    var app = require('app');  // Module to control application life.
var BrowserWindow = require('browser-window'); // Module to create native browser window.

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null;

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

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function() {
// Create the browser window.
mainWindow = new BrowserWindow({width: 900, height: 600});

// and load the index.html of the app.
mainWindow.loadURL("path to index.html");

// Emitted when the window is closed.
mainWindow.on('closed', function() {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
});

(“index.html 的路径”替换为实际脚本中的真实路径)

这是 package.json 文件:

 {
"name": "overboard",
"version": "1.0.0",
"description": "",
"main": "main.js",
"dependencies": {
"electron-forge": "^5.2.4",
"electron-packager": "^14.2.1",
"pretty-bytes": "^2.0.1"
},
"devDependencies": {
"electron-prebuilt": "^0.35.2"
},
"scripts": {
"init": "npm install",
"start": "electron main.js"
},
"author": "Me",
"license": "ISC"
}

感谢您提前提供的任何帮助,非常感谢。

最佳答案

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

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow = null;

// Quit when all windows are closed.
app.on("window-all-closed", function() {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform != "darwin") {
app.quit();
}
});

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on("ready", function() {
// Create the browser window.
mainWindow = new BrowserWindow({ width: 900, height: 600 });

// and load the index.html of the app.
// Not sure where your index.html is placed but if you are using Electron-quick-starter then this will be right.
// Plus mainWindow.loadURL("https://github.com") not for loading the local file but for loading the url at your browser.

mainWindow.loadFile("./index.html");


// Emitted when the window is closed.
mainWindow.on("closed", function() {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
});

Electron 构建很久以前就已重命名为 Electron 。所以你应该更新你的 package.json

 {
"name": "overboard",
"version": "1.0.0",
"description": "",
"main": "main.js",
"dependencies": {
"pretty-bytes": "^2.0.1"
},
"devDependencies": {
"electron": "latest",
"electron-forge": "latest",
"electron-packager": "latest",
},
"scripts": {
"init": "npm install",
"start": "electron ."
},
"author": "Me",
"license": "ISC"
}

请删除您的 node_modulespackage-lock.json并尝试 npm installnpm start

关于javascript - 在 Windows 10 上尝试使用 CMD 将 Electron 项目编译为 .exe 时,Electron-packager 返回 "Response code 404 (Not Found)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60428886/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com