Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: WeChat mini globalThis is not defined in browser bundle #1797

Closed
Diven-xinhai opened this issue Feb 26, 2024 · 11 comments · Fixed by #1885
Closed

[Bug]: WeChat mini globalThis is not defined in browser bundle #1797

Diven-xinhai opened this issue Feb 26, 2024 · 11 comments · Fixed by #1885
Labels

Comments

@Diven-xinhai
Copy link

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

image
image

Debug logs

.

@Diven-xinhai
Copy link
Author

image

@robertsLando
Copy link
Member

Could you try to add this to the mqttjs bundle?

  globalThis = globalThis || {};

@robertsLando robertsLando changed the title [Bug]: [Bug]: WeChat mini globalThis is not defined in browser bundle Feb 26, 2024
@Diven-xinhai
Copy link
Author

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?

@robertsLando
Copy link
Member

robertsLando commented Feb 27, 2024

@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
Copy link
Author

@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

@robertsLando
Copy link
Member

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

@timzaak
Copy link
Contributor

timzaak commented Jun 6, 2024

MQTTjs Version
5.3.6

TypeError: Cannot set property 'AbortSignal' of undefined

Another issue about this is NervJS/taro#15580

@robertsLando
Copy link
Member

@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
Copy link
Contributor

timzaak commented Jun 7, 2024

@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.

https://github.com/chrisguttandin/worker-timers/blob/8f73b936a20073a809b180d4557c657f26e4e7fa/src/factories/load-or-return-broker.ts#L9

image

@robertsLando
Copy link
Member

@timzaak You can disable using worker timer with timerVariant option

@timzaak
Copy link
Contributor

timzaak commented Jun 11, 2024

@timzaak You can disable using worker timer with timerVariant option

@robertsLando That works. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants