error running simple electron program - javascript

a few days ago I started to learn about electron and I started to make a small project to download youtube videos to test the things around. Here is the code
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);
}
I looked into devtool console and this is the error that shows up. Does this look like a installation error?
File not found (file:///c:/temp/Electron/YouTubeDownloader/node_modules/electron/dist/resources/electron.asar/browser/rpc-server.js
Stack Trace:
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)

I fixed the npmjs.com/package/youtube-dl issue by download the latest youtube-dl exe from https://youtube-dl.org/downloads/latest/youtube-dl.exe, then putting it in node_modules\youtube-dl\bin

Related

Solc Maximum call stack size exceeded at Object.$db [as dynCall_viiiiii]

When I try to compile my contract I get a maximum call stack size exceeded error and cannot figure this out. Any insight would be greatly appreciated
Error
RangeError: Maximum call stack size exceeded
at Object.$db [as dynCall_viiiiii] (C:\Users\molli\Desktop\Coding\Udemy\Solidity Course\inbox\node_modules\[4msolc[24m\soljson.js:12:120931)
at invoke_viiiiii (C:\Users\molli\Desktop\Coding\Udemy\Solidity Course\inbox\node_modules\[4msolc[24m\soljson.js:1:1118207)
at Array.pva (C:\Users\molli\Desktop\Coding\Udemy\Solidity Course\inbox\node_modules\[4msolc[24m\soljson.js:13:29030)
at Object.M9a [as dynCall_vi] (C:\Users\molli\Desktop\Coding\Udemy\Solidity Course\inbox\node_modules\[4msolc[24m\soljson.js:12:99033)
at invoke_vi (C:\Users\molli\Desktop\Coding\Udemy\Solidity Course\inbox\node_modules\[4msolc[24m\soljson.js:1:1115011)
at Array.xta (C:\Users\molli\Desktop\Coding\Udemy\Solidity Course\inbox\node_modules\[4msolc[24m\soljson.js:10:704784)
at Object.Dfb [as dynCall_iii] (C:\Users\molli\Desktop\Coding\Udemy\Solidity Course\inbox\node_modules\[4msolc[24m\soljson.js:12:130740)
at invoke_iii (C:\Users\molli\Desktop\Coding\Udemy\Solidity Course\inbox\node_modules\[4msolc[24m\soljson.js:1:1119442)
at Array.vta (C:\Users\molli\Desktop\Coding\Udemy\Solidity Course\inbox\node_modules\[4msolc[24m\soljson.js:10:703080)
at Object.Yfb [as dynCall_iiiiii] (C:\Users\molli\Desktop\Coding\Udemy\Solidity Course\inbox\node_modules\[4msolc[24m\soljson.js:12:131900)
Inbox.sol
pragma solidity ^0.4.17;
contract Inbox {
string public message;
constructor(string initialMessage) public {
message = initialMessage;
}
function setMessage(string newMessage) public {
message = newMessage;
}
}
compile.js
const path = require('path');
const fs = require('fs');
const solc = require('solc');
const inboxPath = path.resolve(__dirname, 'contracts', 'Inbox.sol');
const source = fs.readFileSync(inboxPath, 'utf8');
module.exports = solc.compile(source, 1).contracts[':Inbox'];
I faced the same problem.
I was able to solve it by downgrading the module version.
The version when I succeed is below.
"ganache-cli": "^6.12.1",
"mocha": "^8.2.1",
"solc": "^0.4.17",
"web3": "^1.0.0-beta.26"

nodejs and twitter api error ' Error: Bad Twitter streaming request: 404 '

Hello i want to create a bot who will automatically send a message to the men who follow you
var Twit = require('twit');
var config = require('./config');
var T = new Twit(config);
var stream = T.stream('user');
stream.on('follow', followedMessage);
function followedMessage(eventMsg) {
console.log('+1 follow');
var fs = require('fs');
var json = JSON.parse(eventMsg);
fs.writeFile("tweet.json", json)
}
but when i start the app i got this error
throw er; // Unhandled 'error' event
^
Error: Bad Twitter streaming request: 404
at Object.exports.makeTwitError (C:\Users\guill\Desktop\Programmation\welcomemessage-V1.0.0\node_modules\twit\lib\helpers.js:74:13)
at Request.<anonymous> (C:\Users\guill\Desktop\Programmation\welcomemessage-V1.0.0\node_modules\twit\lib\streaming-api-connection.js:96:29)
at Request.emit (events.js:327:22)
at IncomingMessage.<anonymous> (C:\Users\guill\Desktop\Programmation\welcomemessage-V1.0.0\node_modules\request\request.js:1076:12)
at Object.onceWrapper (events.js:421:28)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1221:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on StreamingAPIConnection instance at:
at Request.<anonymous> (C:\Users\guill\Desktop\Programmation\welcomemessage-V1.0.0\node_modules\twit\lib\streaming-api-connection.js:99:14)
at Request.emit (events.js:327:22)
[... lines matching original stack trace ...]
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: null,
allErrors: [],
twitterReply: '',
statusCode: 404
}
someone can help me ?
Replace:
var stream = T.stream('user');
With
var stream = T.stream('statuses/filter', { track: '#<your_twitter_username>' });
Thanks to Asaolu Elijah Response on github issue
i dont think that T.stream('user'); is still working now, i have a mission now to built a bot for a client and i had the same problem,
Try to use T.stream('statuses/filter'), or T.stream('sample')

TypeError: Cannot read property 'interface' of undefined

my init.js file
var web3 = require('web3');
fs = require('fs');
solc = require('solc');
web3 = new web3(new web3.providers.HttpProvider("http://localhost:8545"));
code = fs.readFileSync('kyc.sol').toString();
//contract = web3.eth.compile.solidity(code);
contract = solc.compile(code);
function after2Delay() {
contractInstance = kycContract.at(deployedContract.address);
console.log(contractInstance.address);
}
function afterDelay() {
abiDefinition = JSON.parse(contract.contracts[':kyc'].interface);
byteCode = contract.contracts[':kyc'].bytecode;
kycContract = web3.eth.contract(abiDefinition);
deployedContract = kycContract.new({data: byteCode, from: web3.eth.accounts[0], gas: 4700000});
setTimeout(after2Delay, 3000);
}
setTimeout(afterDelay, 8000);
After I run rpc using ganache-cli . I run the above code using node init.js . I'm getting following error
(function (exports, require, module, __filename, __dirname) { var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=typeof window==="object";var ENVIRONMENT_IS_WORKER=typeof importScripts==="function";var ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;var ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(ENVIRONMENT_IS_NODE){if(!Module["print"])Module["print"]=function print(x){process["stdout"].write(x+"\n")};if(!Module["printErr"])Module["printErr"]=function printErr(x){process["stderr"].write(x+"\n")};var nodeFS=require("fs");var nodePath=require("path");Module["read"]=function read(filename,binary){filename=nodePath"normalize";var ret=nodeFS["readFileSy
TypeError: Cannot read property 'interface' of undefined
at Timeout.afterDelay [as _onTimeout] (/Users/pc/Documents/Programs/KYC-chain-master/root/init.js:16:59)
at ontimeout (timers.js:458:11)
at tryOnTimeout (timers.js:296:5)
at Timer.listOnTimeout (timers.js:259:5)
I've read it from here that the problem could be solved my making contract name same as file name. My contract name and file name are same i.e kyc
How to resolve this issue ?

Run python script using node js error no 22

I'm using node.js to run a python script through the web browser. below is the ScriptRunner.js code.
var PythonShell = require('python-shell');
var path = require('path');
exports.runScript = function() {
var options = {
scriptPath: 'D:\L4Project\working code\finalproject\routes'
};
PythonShell.run('sensitive2.py',options, function (err, results) {
if (err) throw err;
console.log('results: %j', results);
});
}
when I run the script in browser it returns error message like below.
D:\L4Project\working code\finalproject\routes\scriptRunner.js:10
if (err) throw err;
^
outes\sensitive2.py': [Errno 22] Invalid argumentg codeinalproject at PythonShell.parseError (D:\L4Project\working code\finalproject\node_modules\python-shell\index.js:191:17)
at terminateIfNeeded (D:\L4Project\working code\finalproject\node_modules\python-shell\index.js:98:28)
at ChildProcess.<anonymous> (D:\L4Project\working code\finalproject\node_modules\python-shell\index.js:89:9)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
I have googles lot and nothing worked. Can Somebody help me to solve the problem?

Metadata of ffmpeg is undefined in electron app

I correctly installed ffmpeg I'm able to check it by writing ffmpeg in cmd which give me this result
Now in my electron app in my index.html I'm geting input from user and sending custom event to electron side of app which lays in index.js entry point
index.html
<script>
const electron = require('electron');
const { ipcRenderer } = electron;
document.querySelector('form').addEventListener('submit', (e) => {
e.preventDefault();
const { path } = document.querySelector('input').files[0];
ipcRenderer.send('video:submit', path);
});
</script>
and using ffmpeg.ffprobe I'm trying to get metadata of video updated to input in electron side like so:
const electron = require('electron');
const ffmpeg = require('fluent-ffmpeg');
const { app, BrowserWindow, ipcMain } = electron;
app.on('ready', () => {
const mainWindow = new BrowserWindow({});
mainWindow.loadURL(`file://${__dirname}/index.html`);
});
ipcMain.on('video:submit', (event, path) => {
ffmpeg.ffprobe(path, (err, metadata) => {
console.log(metadata);
//console.log(metadata.format.duration);
});
});
And it console that metadata is undefined, when I uncomment console.log(metadata.format.duration) it says
typeError: cannot read property
'format' of undefined
What I'm doing wrong?
So I set two new environment variables and now other error occure when I console.log(error):
{ Error: spawn C:\Users\Borys\Documents\videoinfo\ffmpeg\bin ENOENT
at exports._errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
at onErrorNT (internal/child_process.js:374:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawn C:\\Users\\Borys\\Documents\\videoinfo\\ffmpeg\\bin',
path: 'C:\\Users\\Borys\\Documents\\videoinfo\\ffmpeg\\bin',
spawnargs:
[ '-show_streams',
'-show_format',
'C:\\Users\\Borys\\Documents\\portfolio\\img\\header_video.mp4' ] }`
( I had to paste it as code because it was saying that my post containt code that is not properly formatted)
Alright thanks to #Alexander Leithner and this question I figured it out. So error was my environment variables which should be:
FFMPEG_PATH with value of path to ffmeg.exe
FFPROBE_PATH with value of path to ffprobe.exe
PATH with value of C:.......\ffmpeg\bin

Categories