MQTT.js icon indicating copy to clipboard operation
MQTT.js copied to clipboard

In the WeChat mini program, the IDE throw error

Open worldsoon opened this issue 1 year ago • 8 comments

微信截图_20230927161006

When developing a project with WeChat mini program, I want to import the MQTT , but I found that the WeChat mini program's IDE throw error

MQTT version: 5.0.5

worldsoon avatar Sep 27 '23 08:09 worldsoon

if I use v4.2.1,it will work well

worldsoon avatar Sep 27 '23 08:09 worldsoon

what's the content of './lib/mqtt'?

robertsLando avatar Sep 27 '23 11:09 robertsLando

god! me too! why every version not work in WeChat mini program!! goddamn!

blusewang avatar Sep 28 '23 00:09 blusewang

what's the content of './lib/mqtt'?

image

This is the file for the dist directory after build it. Because WeChatmini programs do not support import by npm, so only be import by source file, like import mqtt from "mqtt/dist/mqtt.min.js"

worldsoon avatar Sep 28 '23 01:09 worldsoon

god! me too! why every version not work in WeChat mini program!! goddamn!

version 4.2.1 will work that import by bundle file

worldsoon avatar Sep 28 '23 01:09 worldsoon

what's the content of './lib/mqtt'?

In addition, from v4.2.2 to 4.3.7,after reading the source code, I found that it misjudged the environment of wechat and mistaken it for node

worldsoon avatar Sep 28 '23 01:09 worldsoon

@worldsoon refer it : https://github.com/xuhongv/WeChatAirkiss

xuhongv avatar Sep 28 '23 01:09 xuhongv

I found that it misjudged the environment of wechat and mistaken it for node

Would you like to submit a PR to fix this? Maybe the error comes from: https://github.com/mqttjs/MQTT.js/blob/main/src/lib/is-browser.ts

robertsLando avatar Oct 19 '23 09:10 robertsLando

Try with 5.3.6

robertsLando avatar Feb 26 '24 09:02 robertsLando