LuanRT / YouTube.js

A JavaScript client for YouTube's private API, known as InnerTube.
https://ytjs.dev
MIT License
3.5k stars 220 forks source link

10.0.0 Export "setGlobalDispatcher" not found in module "undici" #666

Open Xkonti opened 3 months ago

Xkonti commented 3 months ago

Steps to reproduce

I tried to use the livechat example, which works on 9.4.0. Here's my code:

import { Innertube, UniversalCache, YTNodes } from 'youtubei.js';
import { ChatAction } from 'youtubei.js/dist/src/parser/youtube/LiveChat';

export async function initYoutube() {

    const yt = await Innertube.create({cache: new UniversalCache(false), generate_session_locally: true});

    const search = await yt.search('Xkonti livestream', {
        features: ['live'],
        upload_date: 'today',
    });

    console.log('Searched for items: ', search)

    const info = await yt.getInfo(search.videos[0].as(YTNodes.Video).id);

    console.log('Selected item: ', search)

    const livechat = info.getLiveChat();

    livechat.on('chat-update', (action: ChatAction) => {
        console.log('Received YT chat update event');
        if (action.is(YTNodes.AddChatItemAction)) {
            const item = action.as(YTNodes.AddChatItemAction).item;

            if (!item)
                return console.info('Action did not have an item.', action);

            const hours = new Date(item.hasKey('timestamp') ? item.timestamp : Date.now()).toLocaleTimeString('en-US', {
                hour: '2-digit',
                minute: '2-digit'
            });

            switch (item.type) {
                case 'LiveChatTextMessage':
                    console.info(
                        `${item.as(YTNodes.LiveChatTextMessage).author?.is_moderator ? '[MOD]' : ''}`,
                        `${hours} - ${item.as(YTNodes.LiveChatTextMessage).author?.name.toString()}:\n` +
                        `${item.as(YTNodes.LiveChatTextMessage).message.toString()}\n`
                    );
                    break;
                case 'LiveChatPaidMessage':
                    console.info(
                        `${item.as(YTNodes.LiveChatPaidMessage).author?.is_moderator ? '[MOD]' : ''}`,
                        `${hours} - ${item.as(YTNodes.LiveChatPaidMessage).author.name.toString()}:\n` +
                        `${item.as(YTNodes.LiveChatPaidMessage).message.toString()}\n`,
                        `${item.as(YTNodes.LiveChatPaidMessage).purchase_amount}\n`
                    );
                    break;
                case 'LiveChatPaidSticker':
                    console.info(
                        `${item.as(YTNodes.LiveChatPaidSticker).author?.is_moderator ? '[MOD]' : ''}`,
                        `${hours} - ${item.as(YTNodes.LiveChatPaidSticker).author.name.toString()}:\n` +
                        `${item.as(YTNodes.LiveChatPaidSticker).purchase_amount}\n`
                    );
                    break;
                default:
                    console.debug(action);
                    break;
            }
        }
    });

    livechat.start();
}

After executing await initYoutube(); the error shows up :(

Failure Logs

1 | (function (entry, fetcher)
    ^
SyntaxError: Export named 'setGlobalDispatcher' not found in module 'undici'.
1 | (function (entry, fetcher)
    ^
SyntaxError: Export named 'setGlobalDispatcher' not found in module 'undici'.

Expected behavior

It should work just like it does on 9.4.0.

Current behavior

Currently there are errors.

Version

Default

Anything else?

Runtime: Bun 1.1.13 OS: Windows WebFramework: Elysia.js

Checklist

LuanRT commented 3 months ago

Try changing that import to youtubei.js/web.

hexxt-git commented 1 month ago

same here

ixnoahlive commented 1 month ago

Luan's fix works, however when doing things with actions you'll get this error: image

See code: image