Javascript 未捕获(承诺中)类型错误:spawn不是函数
我有点困在这里了。我正在使用我的action creator中的redux thunk提交一个异步请求,如下所示:Javascript 未捕获(承诺中)类型错误:spawn不是函数,javascript,reactjs,asynchronous,redux,react-redux,Javascript,Reactjs,Asynchronous,Redux,React Redux,我有点困在这里了。我正在使用我的action creator中的redux thunk提交一个异步请求,如下所示: export const downloadFromYoutube = (download) => { console.log("Hello"); return dispatch => { var YoutubeMp3Downloader = require('youtube-mp3-downloader'); var YD = ne
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");
}
};
但我总是会遇到以下错误:
TypeError:spawn不是函数
我在electron中使用React/Redux。我还应该提到,当我使用超时函数而不是下载函数时,redux thunk确实起作用。然而,上面的代码和youtube downloader库的使用在我把它放在一个普通的javascript/nodejs文件中并执行它时也能正常工作,因此它似乎与我在React中处理承诺的方式有关
以下是完整的错误日志:
未捕获(承诺中)TypeError:spawn不是函数(…)(匿名)
函数)@processor.js:135proto.\u getFfmpegPath@
capabilities.js:90proto.\u@
processor.js:115proto.availableFormats.proto.getAvailableFormats@
capabilities.js:514(匿名函数)@capabilities.js:564fn@
async.js:746(匿名函数)@async.js:1213(匿名函数)@
async.js:166(匿名函数)@async.js:706(匿名函数)@
async.js:167async.瀑布@async.js:710proto.\u@
capabilities.js:561(匿名函数)@processor.js:287fn@
async.js:746(匿名函数)@async.js:1213(匿名函数)@
async.js:166(匿名函数)@async.js:706(匿名函数)@
async.js:167async.瀑布@async.js:710proto.\u@
processor.js:284proto.exec.proto.execute.proto.run@
processor.js:420proto.saveToFile.proto.save@recipes.js:28(匿名)
函数)@YoutubeMp3Downloader.js:151emitOne@events.js:77emit@
events.js:169(匿名函数)@index.js:1131@
events.js:77emit@events.js:169ClientRequest.\u connect@
request.js:235(匿名函数)@request.js:128
Spawn是nodejs的一个构造。React as框架没有该方法。该库将用于服务器端(nodejs)。您可以公开可以通过react触发的http api。http api随后可以触发nodejs服务器中的库。摘自文章: 使用Socket.IO 服务器端代码
var io = require('socket.io').listen(80); // initiate socket.io server
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' }); // Send data to client
// wait for the event raised by the client
socket.on('my other event', function (data) {
console.log(data);
});
});
和客户端:
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost'); // connec to server
socket.on('news', function (data) { // listen to news event raised by the server
console.log(data);
socket.emit('my other event', { my: 'data' }); // raise an event on the server
});
</script>
var socket=io.connect('http://localhost'); // 连接到服务器
on('news',函数(数据){//侦听服务器引发的新闻事件
控制台日志(数据);
emit('my other event',{my:'data'});//在服务器上引发事件
});
非常感谢,这就解释了一切。因此,我需要从动作创建者那里调用我的电子渲染器进程。如果你知道怎么做的话,我已经提交了进一步说明这个问题的文件,因为既然你已经回答了我的问题,它在这里似乎不相关。