Closed Diven-xinhai closed 2 months ago
Could you try to add this to the mqttjs bundle?
globalThis = globalThis || {};
Could you try to add this to the mqttjs bundle?
globalThis = globalThis || {};
Sorry, I don't quite understand what you mean. Could you please specify where or in which file I should add?
@Diven-xinhai node_modules/mqtt/dist/mqtt.esm.js
Alternatively you could also try to add that in a script tag in your index.html file
@Diven-xinhai
node_modules/mqtt/dist/mqtt.esm.js
Alternatively you could also try to add that in a script tag in your index.html file
I tried to add globalThis = globalThis || {} in index.html or mqtt.esm.js; But it didn't work. It's the same error
The problem is that for some reason when you are running this in wechat mini globalThis
is not defined (it should be in all browsers BTW) so you should try fixing it within your bundle someway because I don't have a way to test this out
MQTTjs Version 5.3.6
TypeError: Cannot set property 'AbortSignal' of undefined
Another issue about this is https://github.com/NervJS/taro/issues/15580
@timzaak I don't use wechat and I also have no way to test this so please feel free to open a PR to fix this issue.
@timzaak I don't use wechat and I also have no way to test this so please feel free to open a PR to fix this issue.
@robertsLando I solved this by import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
before import mqtt
but worker-timers uses new Blob()
, Wechat miniprogram do not support Blob, it should be replaced by ArrayBuffer.
@timzaak You can disable using worker timer with timerVariant
option
@timzaak You can disable using worker timer with
timerVariant
option
@robertsLando That works. Thanks
引入了import "abortcontroller-polyfill/dist/abortcontroller-polyfill-only";
还是报错
TypeError: Cannot destructure property 'AbortController' of '(intermediate value)(intermediate value)(intermediate value)' as it is undefined.
在项目最开始初始化的地方引入。 app.ts or main.ts
你用哪个版本的mqtt.js,我这试了还不行,引入了 abortcontroller-polyfill/dist/abortcontroller-polyfill-only
打包会报错, SyntaxError: Unexpected token ; onabort;
"mqtt": "5.7.3"
Starting from next MQTTjs version you will need another polifilly in order to make it work with WeChat. See docs
MQTTjs Version
5.3.6
Broker
mqtt
Environment
NodeJS
Description
The latest version 5.3.6 reported an error in the wechat mini program, the error message is as follows: TypeError: Cannot read property 'AbortController' of undefined
Minimal Reproduction
Debug logs
.