simon300000 / bilibili-live-ws

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

关于 【Could not resolve "pako"】 与 【Dynamic require of "buffer" is not supported】的问题 #266

Closed LoveLoliii closed 2 years ago

LoveLoliii commented 2 years ago

您好~ 在vite-react-electron模板构建的一个electron项目中, 在渲染进程中使用import { LiveWS } from 'bilibili-live-ws/browser' 运行提示:

X [ERROR] Could not resolve "pako"

    node_modules/bilibili-live-ws/src/inflate/browser.js:6:23:
      6 │ const pako_1 = require("pako");

之后我就yarn add pako 再次运行后 提示:

Uncaught Error: Dynamic require of "buffer" is not supported
    at chunk-ACCAMVX6.js?v=d5e4b460:12:9
    at node_modules/bilibili-live-ws/src/inflate/browser.js (browser.js:4:18)
    at __require2 (chunk-ACCAMVX6.js?v=d5e4b460:18:50)
    at node_modules/bilibili-live-ws/src/browser.js (browser.js:4:19)
    at __require2 (chunk-ACCAMVX6.js?v=d5e4b460:18:50)
    at node_modules/bilibili-live-ws/browser.js (browser.js:17:14)
    at __require2 (chunk-ACCAMVX6.js?v=d5e4b460:18:50)
    at dep:bilibili-live-ws_browser:1:16

browser.js 的第4行是这个:const buffer_1 = require("buffer");

simon300000 commented 2 years ago

试试看yarn add buffer?

LoveLoliii commented 2 years ago

还是同样的错误

Dynamic require of "buffer" is not supported
simon300000 commented 2 years ago

哎 试试bilibili-live-ws@6.2.1

LoveLoliii commented 2 years ago

哎 试试bilibili-live-ws@6.2.1

查了一圈 看起来像是vite pre-building 过程中的问题。 这里看见的

simon300000 commented 2 years ago

喔唷 那你解决了吗 还有一个办法是submodule然后直接作为ts import,ts代码应该是合格esm

simon300000 commented 2 years ago

哦不 esm似乎要加上扩展名 可能还不行😵‍💫

LoveLoliii commented 2 years ago

哦不 esm似乎要加上扩展名 可能还不行😵‍💫

这块还不太懂 我去学学😀

LoveLoliii commented 2 years ago

喔唷 那你解决了吗 还有一个办法是submodule然后直接作为ts import,ts代码应该是合格esm

我悟了 我不在渲染进程用了 我去主进程用。

simon300000 commented 2 years ago

没用过vite 你试试看👀

LoveLoliii commented 2 years ago

在electron的主进程用 是没问题的

simon300000 commented 2 years ago

太好啦!虽然有点可惜😭