typescript 我无法使用nestjs访问ytdl-core函数

eulz3vhy  于 2023-01-18  发布在  TypeScript
关注(0)|答案(1)|浏览(169)

我正在用nestjs和ytdl-core构建一个youtube下载,当我导入它时,它给出了以下错误

[Nest] 3876  - 01/17/2023, 10:55:06 AM   ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'getInfo')
TypeError: Cannot read properties of undefined (reading 'getInfo')
    at DawnloadService.create (C:\Users\azure\www\backend\youtube-dawnload\src\dawnload\dawnload.service.ts:10:10)
    at DawnloadController.create (C:\Users\azure\www\backend\youtube-dawnload\src\dawnload\dawnload.controller.ts:11:33)
    at C:\Users\azure\www\backend\youtube-dawnload\node_modules\@nestjs\core\router\router-execution-context.js:38:29
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at C:\Users\azure\www\backend\youtube-dawnload\node_modules\@nestjs\core\router\router-execution-context.js:46:28
    at C:\Users\azure\www\backend\youtube-dawnload\node_modules\@nestjs\core\router\router-proxy.js:9:17

每次我调用这个函数的时候,当我运行它的时候,我会得到这个错误。

import { Injectable } from '@nestjs/common';
import { CreateDawnloadDto } from './dto/create-dawnload.dto';
import ytdl from 'ytdl-core';
import fs from 'node:fs';

@Injectable()
export class DawnloadService {
  async create(createDawnloadDto: CreateDawnloadDto) {

    ytdl.getInfo("https://www.youtube.com/watch?v=har3c93pJe0");

    return createDawnloadDto.videoURL
  }
}
kkbh8khc

kkbh8khc1#

ytdl-core不使用默认导出。您应该使用import * as ytdl from 'ytdl-core'

相关问题