Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TypeError:无法读取属性';视频';未定义的_Javascript - Fatal编程技术网

Javascript TypeError:无法读取属性';视频';未定义的

Javascript TypeError:无法读取属性';视频';未定义的,javascript,Javascript,我正在使用yt search模块搜索YouTube内容,下面是我使用的一些代码: const yts = require("yt-search") await yts( "yorushika", function ( err, r ) { console.log(r.videos.length) } 这将产生以下错误 TypeError: Cannot read property 'videos' of undefined at /root/pkb/commands/mus

我正在使用
yt search
模块搜索YouTube内容,下面是我使用的一些代码:

const yts = require("yt-search")
await yts( "yorushika", function ( err, r ) {
     console.log(r.videos.length)
}

这将产生以下错误

TypeError: Cannot read property 'videos' of undefined
    at /root/pkb/commands/music/play.js:19:27
    at l (/root/pkb/node_modules/yt-search/dist/yt-search.min.js:1:1287)
    at /root/pkb/node_modules/yt-search/dist/yt-search.min.js:1:6750
    at /root/pkb/node_modules/async.util.parallel/index.js:20:9
    at /root/pkb/node_modules/async.util.once/index.js:6:12
    at /root/pkb/node_modules/async.util.eachoflimit/index.js:36:25
    at /root/pkb/node_modules/async.util.onlyonce/index.js:6:12
    at /root/pkb/node_modules/async.util.parallel/index.js:17:13
    at /root/pkb/node_modules/async.util.restparam/index.js:14:29
    at /root/pkb/node_modules/yt-search/dist/yt-search.min.js:1:6669

r是


我想修复错误,但不知道如何修复(一天前,
npm安装yt)-search@latest
解决了这个问题,但今天它不起作用了)。

检查
err
可能是个好主意。尝试在
console.log(r.videos.length)
之前添加
if(err)throw err
。您现在收到了什么错误消息?您提供的代码似乎工作正常。正如已经指出的,也许你得到的是一个错误而不是视频数据?

{
  videos: [
    {
      type: 'video',
      title: 'ヨルシカ - 夜行 (OFFICIAL VIDEO)',
      description: 'ヨルシカ - 夜行Yorushika - Night Journey作詞作曲、編曲(Words and Music): n-bunaVocal: suis Official Sitehttp://yorushika ...',
      url: 'https://youtube.com/watch?v=MH5noJJfqDY',
      videoId: 'MH5noJJfqDY',
      seconds: 219,
      timestamp: '3:39',
      duration: [Object],
      views: 949413,
      thumbnail: 'https://i.ytimg.com/vi/MH5noJJfqDY/default.jpg',
      image: 'https://i.ytimg.com/vi/MH5noJJfqDY/hqdefault.jpg',
      ago: '2 days ago',
      author: [Object]
    },
    {
      type: 'video',
      title: 'ヨルシカ - 言って。(Music Video)',
      description: 'ヨルシカ 「言って。」Yorushika - Say it作詞、作曲、編曲:n-bunaVocal:suisMusic Video Directed by 大鳥http://yorushika.com/ヨル ...',
      url: 'https://youtube.com/watch?v=F64yFFnZfkI',
      videoId: 'F64yFFnZfkI',
      seconds: 244,
      timestamp: '4:04',
      duration: [Object],
      views: 57577275,
    //and more
}