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

Open
Diven-xinhai opened this issue Feb 26, 2024 · 6 comments
Open

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

Diven-xinhai opened this issue Feb 26, 2024 · 6 comments
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

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

No branches or pull requests

2 participants