Uncaught (in promise) TypeError: spawn is not a function
Uncaught (in promise) TypeError: spawn is not a function
我有点卡在这里。我在我的 action creator 中提交带有 redux-thunk 的异步请求,如下所示:
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 is not a function
我在 electron 中使用 React/Redux。我还应该提到 redux-thunk 在我使用超时功能而不是下载功能时确实有效。但是,当我将上面的代码和 youtube 下载器库的使用放在一个普通的 javascript / nodejs 文件中并执行它时,它也可以正常工作,所以它似乎与我处理承诺的方式有关反应。
这是完整的错误日志:
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 是 nodejs 的构造。作为框架的 React 没有方法。该库将在服务器端(nodejs)中使用。您可以公开一个可以通过反应触发的 http api 。 http api 然后可以触发 nodejs 服务器中的库。
摘自 this 文章:
使用Socket.IO
Server-side代码
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);
});
});
和client-side:
<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>
我有点卡在这里。我在我的 action creator 中提交带有 redux-thunk 的异步请求,如下所示:
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 is not a function
我在 electron 中使用 React/Redux。我还应该提到 redux-thunk 在我使用超时功能而不是下载功能时确实有效。但是,当我将上面的代码和 youtube 下载器库的使用放在一个普通的 javascript / nodejs 文件中并执行它时,它也可以正常工作,所以它似乎与我处理承诺的方式有关反应。
这是完整的错误日志:
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 是 nodejs 的构造。作为框架的 React 没有方法。该库将在服务器端(nodejs)中使用。您可以公开一个可以通过反应触发的 http api 。 http api 然后可以触发 nodejs 服务器中的库。
摘自 this 文章:
使用Socket.IO
Server-side代码
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);
});
});
和client-side:
<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>