MQTT.js import error: This browser lacks typed array (Uint8Array) support which is required by buffer
v5.x. Use buffer
v4.x if you require old browser support.
#10105
-
hi. I tried importing MQTT.js with a single js file mqtt.min.js like this, and tried to run and got this errror. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I'm guessing this is because But actually, it looks like the latest version of browserify's Buffer uses |
Beta Was this translation helpful? Give feedback.
-
I'm getting this with babel-standalone:
|
Beta Was this translation helpful? Give feedback.
I'm guessing this is because
MQTT.js
contains a browserified version of Node.js'sBuffer
, and that package tries to change prototypes using__proto__
. This doesn't work because, unlike browsers, Deno doesn't allow__proto__
to be overwritten (relevant issue). One way to fix this (as mentioned here) is to replace all instances ofobj.__proto__ = newPrototype
withObject.setPrototypeOf(obj, newPrototype)
.But actually, it looks like the latest version of browserify's Buffer uses
setPrototypeOf
instead of__proto__
, so you may just be able to ask the maintainer of https://github.com/mqttjs/MQTT.js to re-browserify the package and publish a new version.