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

Electron 和 Vue3开发打包的时候会出现报错 #23

Closed happys2333 closed 1 year ago

happys2333 commented 1 year ago

报错内容如下:

 error  in ./node_modules/blive-message-listener/dist/chunk-XFSH6FXD.mjs

Module parse failed: Unexpected token (159:29)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|     timestamp: rawData[0][4],
|     lottery: rawData[0][9] !== 0,
>     emoticon: rawData[0][13]?.emoticon_unique ? {
|       id: rawData[0][13].emoticon_unique,
|       height: rawData[0][13].height,

 @ ./node_modules/blive-message-listener/dist/index.mjs 1:0-3:30 20:2-11

 error  in ./node_modules/tiny-bilibili-ws/dist/index.cjs

Module parse failed: Unexpected token (20:45)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| function brotliDecompress(buf, options) {
|   return new Promise((resolve, reject) => {
>     node_zlib.brotliDecompress(buf, options ?? {}, handler(resolve, reject));
|   });
| }

 @ ./node_modules/blive-message-listener/dist/index.mjs 6:0-47 19:19-30

自我排查应该是webpack没有能解析mjs和cjs,不太清楚如何解决 环境:

"electron": "23.1.0",
"vue": "^3.0.0",
"blive-message-listener": "^0.4.4",
ddiu8081 commented 1 year ago

报错信息看起来是有两个 ES2020 的语法不支持编译,试试给 Electron 配置 Babel,或者库的引入方式改用 require 试试:

- import { startListen } from 'blive-message-listener'
+ const { startListen } = require('blive-message-listener')
happys2333 commented 1 year ago

ok,解决了,谢谢