simon300000 / bilibili-live-ws

Bilibili live WebSocket/tcp API
MIT License
316 stars 31 forks source link

Uncaught (in promise) TypeError: packs.flatMap is not a function #235

Closed LoveLoliii closed 2 years ago

LoveLoliii commented 2 years ago

大佬您好。 在electron-vue 项目中使用了 "bilibili-live-ws": "^5.1.1" node -v : v14.17.4 运行过程中提示:

Uncaught (in promise) TypeError: packs.flatMap is not a function
    at Object.exports.decoder (F:\git_pro\muamuamua\node_modules\bilibili-live-ws\src\buffer.js:51)

buffer.js:

return packs.flatMap(pack => {
        if (pack.protocol === 2) {
            return pack.data;
        }
        return pack;
    });

我改成:

packs.forEach(pack => {
        if (pack.protocol === 2) {
            pack = pack.data
        }
    });
    return packs

倒是可以。 不过最近在使用GitHub 的 actions就又出现了。 QAQ

simon300000 commented 2 years ago

哦天呐 看起来是nodejs的版本有些低了

simon300000 commented 2 years ago

我加入了一个polyfill,应该可以解决这个问题吧 bilibili-live-ws@6.1.0

LoveLoliii commented 2 years ago

我加入了一个polyfill,应该可以解决这个问题吧 bilibili-live-ws@6.1.0

感谢大佬!

simon300000 commented 2 years ago

weeee 能用就好

LoveLoliii commented 2 years ago

weeee 能用就好

但是( 用6.1.0 或者6.0.3 会出现下面的错误:

Uncaught NodeError: The "original" argument must be of type function
    at promisify (internal/util.js:206:11)
    at Object.<anonymous> (F:\git_pro\muamuamua\node_modules\bilibili-live-ws\src\inflate\node.js:7:52)
    at Object.<anonymous> (F:\git_pro\muamuamua\node_modules\bilibili-live-ws\src\inflate\node.js:10:3)
    at Module._compile (module.js:642:30)
    at Object.Module._extensions..js (module.js:653:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:504:12)
    at Function.Module._load (module.js:496:3)
    at Module.require (module.js:586:17)
    at require (internal/module.js:11:18)

使用5.1.1的时候是没有出现的

simon300000 commented 2 years ago

😨😨😨😨😨😨😨😨😨

simon300000 commented 2 years ago

居然会这样😨

simon300000 commented 2 years ago

这是electron里面的main,也就是node环境对吧

LoveLoliii commented 2 years ago

这是electron里面的main,也就是node环境对吧

我也不知道哎。electron分成main进程和renderer进程。我实在renderer下使用的。写在这里的

simon300000 commented 2 years ago

破案了 这个调用的有问题,应该调用browser.js

你试一下能不能直接写bilibili-live-ws/browser ?

simon300000 commented 2 years ago

我要检查一下我写的哪里有问题,理论上浏览器应该会用browser

LoveLoliii commented 2 years ago

bilibili-live-ws/browser 好的 我试试 OVO

LoveLoliii commented 2 years ago

破案了 这个调用的有问题,应该调用browser.js

你试一下能不能直接写bilibili-live-ws/browser ?

大佬牛批!可以了!

simon300000 commented 2 years ago

我得写进readme😭

LoveLoliii commented 2 years ago

问题解决惹