Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
4 tasks done
Xkonti opened this issue Jun 13, 2024 · 3 comments
Open
4 tasks done

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

Xkonti opened this issue Jun 13, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@Xkonti
Copy link

Xkonti commented Jun 13, 2024

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

  • I am running the latest version.
  • I checked the documentation and found no answer.
  • I have searched the existing issues and made sure this is not a duplicate.
  • I have provided sufficient information.
@Xkonti Xkonti added the bug Something isn't working label Jun 13, 2024
@LuanRT
Copy link
Owner

LuanRT commented Jun 13, 2024

Try changing that import to youtubei.js/web.

@hexxt-git
Copy link

same here

@ixnoahlive
Copy link

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

See code:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants