ddiu8081 / blive-message-listener

Bilibili live danmu listener with type. 类型友好的 Bilibili 直播间弹幕监听库。
https://npmjs.com/blive-message-listener
MIT License
145 stars 13 forks source link

浏览器中使用的问题 #10

Closed tymon42 closed 2 years ago

tymon42 commented 2 years ago

安装方式

pnpm i blive-message-listener

pnpm dev 报错:

X [ERROR] No matching export in "browser-external:node:net" for import "connect"

    node_modules/.pnpm/tiny-bilibili-ws@0.0.2/node_modules/tiny-bilibili-ws/dist/index.mjs:1:9:
      1 │ import { connect } from 'node:net';
        ╵          ~~~~~~~

X [ERROR] No matching export in "browser-external:node:zlib" for import "brotliDecompress"

    node_modules/.pnpm/tiny-bilibili-ws@0.0.2/node_modules/tiny-bilibili-ws/dist/index.mjs:5:9:
      5 │ import { brotliDecompress as brotliDecompress$1, inflate as inflate$1 } from 'node:zlib';
        ╵          ~~~~~~~~~~~~~~~~

X [ERROR] No matching export in "browser-external:node:zlib" for import "inflate"

    node_modules/.pnpm/tiny-bilibili-ws@0.0.2/node_modules/tiny-bilibili-ws/dist/index.mjs:5:49:
      5 │ import { brotliDecompress as brotliDecompress$1, inflate as inflate$1 } from 'node:zlib';
        ╵                                                  ~~~~~~~

22:54:27 [vite] error while updating dependencies:
Error: Build failed with 3 errors:
node_modules/.pnpm/tiny-bilibili-ws@0.0.2/node_modules/tiny-bilibili-ws/dist/index.mjs:1:9: ERROR: No matching export in "browser-external:node:net" for import "connect"
node_modules/.pnpm/tiny-bilibili-ws@0.0.2/node_modules/tiny-bilibili-ws/dist/index.mjs:5:9: ERROR: No matching export in "browser-external:node:zlib" for import "brotliDecompress"
node_modules/.pnpm/tiny-bilibili-ws@0.0.2/node_modules/tiny-bilibili-ws/dist/index.mjs:5:49: ERROR: No matching export in "browser-external:node:zlib" for import "inflate"
    at failureErrorWithLog (C:\Users\why00\Documents\project\bubblebox-web\node_modules\.pnpm\esbuild@0.14.54\node_modules\esbuild\lib\main.js:1624:15)
    at C:\Users\why00\Documents\project\bubblebox-web\node_modules\.pnpm\esbuild@0.14.54\node_modules\esbuild\lib\main.js:1266:28
    at runOnEndCallbacks (C:\Users\why00\Documents\project\bubblebox-web\node_modules\.pnpm\esbuild@0.14.54\node_modules\esbuild\lib\main.js:1046:63)
    at buildResponseToResult (C:\Users\why00\Documents\project\bubblebox-web\node_modules\.pnpm\esbuild@0.14.54\node_modules\esbuild\lib\main.js:1264:7)
    at C:\Users\why00\Documents\project\bubblebox-web\node_modules\.pnpm\esbuild@0.14.54\node_modules\esbuild\lib\main.js:1377:14
    at C:\Users\why00\Documents\project\bubblebox-web\node_modules\.pnpm\esbuild@0.14.54\node_modules\esbuild\lib\main.js:678:9
    at handleIncomingPacket (C:\Users\why00\Documents\project\bubblebox-web\node_modules\.pnpm\esbuild@0.14.54\node_modules\esbuild\lib\main.js:775:9)
    at Socket.readFromStdout (C:\Users\why00\Documents\project\bubblebox-web\node_modules\.pnpm\esbuild@0.14.54\node_modules\esbuild\lib\main.js:644:7)
    at Socket.emit (node:events:526:28)
    at addChunk (node:internal/streams/readable:315:12)

貌似和这个issues 是同一个原因。
我暂时还不知道有什么解决方法。

ddiu8081 commented 2 years ago

是不是导入路径不对?

在浏览器使用时,需要从 blive-message-listener/browser 导入

import { startListen } from 'blive-message-listener/browser'
tymon42 commented 2 years ago

导入路径没问题。
我回退代码,发现安装 sass 相关的库会复现:

npm install node-sass --save
npm install sass-loader --save
npm install style-loader --save

我暂时也没有思路。
我尝试重构项目,引入这几个包再导入 blive-message-listener/browser 就没有问题了。
很迷……