gpt4 book ai didi

javascript - 运行简单的 Electron 程序时出错

转载 作者:行者123 更新时间:2023-12-03 02:30:26 24 4
gpt4 key购买 nike

几天前,我开始学习 Electron,并开始制作一个小项目来下载 YouTube 视频来测试周围的东西。这是代码

ma​​in.js:

const electron = require(‘electron’);
const path = require(‘path’);
const url = require(‘url’);
const youtubedl = require(‘youtube-dl’);

const {app, BrowserWindow, Menu, ipcMain} = electron;

let mainWindow;

app.on(‘ready’, function()
{
mainWindow = new BrowserWindow({});
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, ‘index.html’),
protocol: ‘file:’,
slashes:true
}));
mainWindow.on(‘closed’, function(){
app.quit();
});

const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
Menu.setApplicationMenu(mainMenu);
});

exports.getUrlInformation=(arg)=>
{
var url = arg;
var options = [];
youtubedl.getInfo(url, options, function(err, urlInformation)
{
if (err) throw err;

mainWindow.webContents.send('UrlInformation', urlInformation);
});
}

index.js:

var {ipcRenderer, remote} = require(‘electron’);
var mainProcess = remote.require("./main.js");

class YouTubeDownloaderForm extends React.Component
{
constructor(props)
{
super(props);
this.state = {url: ‘’};
this.handleAddClick = this.handleAddClick.bind(this);
}
handleAddClick(event)
{
mainProcess.getUrlInformation(this.state.url);
}

我查看了 devtool 控制台,这是显示的错误。这看起来像是安装错误吗?

找不到文件(file:///c:/temp/Electron/YouTubeDownloader/node_modules/electron/dist/resources/electron.asar/browser/rpc-server.js

堆栈跟踪:

Uncaught Error: Could not call remote function ''. Check that the function signature is correct. Underlying error: spawn UNKNOWN
Error: Could not call remote function ''. Check that the function signature is correct. Underlying error: spawn UNKNOWN
at callFunction (C:\temp\Electron\YouTubeDownloader\node_modules\electron\dist\resources\electron.asar\browser\rpc-server.js:257:11)
at EventEmitter.<anonymous> (C:\temp\Electron\YouTubeDownloader\node_modules\electron\dist\resources\electron.asar\browser\rpc-server.js:357:5)
at emitMany (events.js:127:13)
at EventEmitter.emit (events.js:204:7)
at WebContents.<anonymous> (C:\temp\Electron\YouTubeDownloader\node_modules\electron\dist\resources\electron.asar\browser\api\web-contents.js:256:13)
at emitTwo (events.js:106:13)
at WebContents.emit (events.js:194:7)
at callFunction (C:\temp\Electron\YouTubeDownloader\node_modules\electron\dist\resources\electron.asar\browser\rpc-server.js:257:11)
at EventEmitter.<anonymous> (C:\temp\Electron\YouTubeDownloader\node_modules\electron\dist\resources\electron.asar\browser\rpc-server.js:357:5)
at emitMany (events.js:127:13)
at EventEmitter.emit (events.js:204:7)
at WebContents.<anonymous> (C:\temp\Electron\YouTubeDownloader\node_modules\electron\dist\resources\electron.asar\browser\api\web-contents.js:256:13)
at emitTwo (events.js:106:13)
at WebContents.emit (events.js:194:7)
at metaToValue (C:\temp\Electron\YouTubeDownloader\node_modules\electron\dist\resources\electron.asar\renderer\api\remote.js:234:13)
at Object.remoteMemberFunction (C:\temp\Electron\YouTubeDownloader\node_modules\electron\dist\resources\electron.asar\renderer\api\remote.js:118:18)
at YouTubeDownloaderForm.handleAddClick (<anonymous>:42:19)
at HTMLUnknownElement.callCallback (https://unpkg.com/react-dom@16.2.0/umd/react-dom.development.js:580:14)
at Object.invokeGuardedCallbackDev (https://unpkg.com/react-dom@16.2.0/umd/react-dom.development.js:619:16)
at Object.invokeGuardedCallback (https://unpkg.com/react-dom@16.2.0/umd/react-dom.development.js:476:27)
at Object.invokeGuardedCallbackAndCatchFirstError (https://unpkg.com/react-dom@16.2.0/umd/react-dom.development.js:490:43)
at executeDispatch (https://unpkg.com/react-dom@16.2.0/umd/react-dom.development.js:972:19)
at executeDispatchesInOrder (https://unpkg.com/react-dom@16.2.0/umd/react-dom.development.js:994:5)
at executeDispatchesAndRelease (https://unpkg.com/react-dom@16.2.0/umd/react-dom.development.js:1092:5)

最佳答案

我通过从 https://youtube-dl.org/downloads/latest/youtube-dl.exe 下载最新的 youtube-dl exe 修复了 npmjs.com/package/youtube-dl 问题,然后将其放入node_modules\youtube-dl\bin

关于javascript - 运行简单的 Electron 程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48758375/

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