I am bit stuck here. I am submitting an async request with redux-thunk in my action creator which looks like this:
export const downloadFromYoutube = (download) => {
console.log("Hello");
return dispatch => {
var YoutubeMp3Downloader = require('youtube-mp3-downloader');
var YD = new YoutubeMp3Downloader({
"ffmpegPath": "/usr/local/Cellar/ffmpeg/3.2.2/bin/ffmpeg", // Where is the FFmpeg binary located?
"outputPath": "/Users/dominik/Coding/youtube-downloader-papa/downloads", // Where should the downloaded and encoded files be stored?
"youtubeVideoQuality": "highest", // What video quality should be used?
"queueParallelism": 2, // How many parallel downloads/encodes should be started?
"progressTimeout": 2000 // How long should be the interval of the progress reports
});
console.log("Hello");
YD.on("finished", data => dispatch({ type: "FINISHED", payload: data }));
YD.on("error", error => dispatch({ type: "ERROR", payload: error }));
YD.on("progress", progress => dispatch({ type: "PROGRESS", payload: progress }));
// dispatch a "starting" action
// dispatch({ type: "STARTING" });
// start the download
YD.download("UDzGLMLhy80");
}
};
But I am always getting the following error:
TypeError: spawn is not a function
I am using React/Redux in electron. I also should mention redux-thunk does work when I use a timeout function instead of the download function. However, the code above & use of the youtube downloader library also works fine when I just put it in a plain javascript / nodejs file and execute it, so it seems to have something to do with the way I handle promises in React.
Here is the full error log:
Uncaught (in promise) TypeError: spawn is not a function(…)(anonymous function) @ processor.js:135proto._getFfmpegPath @ capabilities.js:90proto._spawnFfmpeg @ processor.js:115proto.availableFormats.proto.getAvailableFormats @ capabilities.js:514(anonymous function) @ capabilities.js:564fn @ async.js:746(anonymous function) @ async.js:1213(anonymous function) @ async.js:166(anonymous function) @ async.js:706(anonymous function) @ async.js:167async.waterfall @ async.js:710proto._checkCapabilities @ capabilities.js:561(anonymous function) @ processor.js:287fn @ async.js:746(anonymous function) @ async.js:1213(anonymous function) @ async.js:166(anonymous function) @ async.js:706(anonymous function) @ async.js:167async.waterfall @ async.js:710proto._prepare @ processor.js:284proto.exec.proto.execute.proto.run @ processor.js:420proto.saveToFile.proto.save @ recipes.js:28(anonymous function) @ YoutubeMp3Downloader.js:151emitOne @ events.js:77emit @ events.js:169(anonymous function) @ index.js:113emitOne @ events.js:77emit @ events.js:169ClientRequest._connect @ request.js:235(anonymous function) @ request.js:128
Spawn is a construct of nodejs. React as a framework does not have the method. This library is to be used in server side (nodejs). You can expose a http api which can be triggered via react. The http api can then trigger the library in nodejs server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With