错误运行简单电子程序

时间:2018-02-13 01:58:40

标签: javascript reactjs youtube electron

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

main.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控制台,这是出现的错误。这看起来像是安装错误吗?

找不到档案(档案:/// 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)

1 个答案:

答案 0 :(得分:1)

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