Support using with ESM in browser
See original GitHub issueCurrently there are no examples for using the project in the browser, so I created a minimal example that creates a connection in a web application bundled using Vite.js, which uses ES modules.
This does not work, for example because the library depends on globals
.
This can be addressed by defining it (see this bug report):
<script>
// @see https://github.com/aws/aws-sdk-js/issues/3673#issuecomment-855205181
var global = global || window;
</script>
However then mqtt-packet/constants.js
is loaded, which depends on the Node.js API. ESM and browser friendly alternative exists: https://www.npmjs.com/package/u8-mqtt-packet
I understand this is a bigger task, so I wanted people to have an issue to upvote.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:16
- Comments:5 (3 by maintainers)
Top Results From Across the Web
"ESM" | Can I use... Support tables for HTML5, CSS3, etc
"Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.
Read more >Using ES Modules in the Browser Today - SitePoint
The Current ES Modules Landscape ... Safari, Chrome, Firefox and Edge all support the ES6 Modules import syntax. Here's what they look like....
Read more >How to use ESM on the web and in Node.js - ByteofDev
Today, Chrome, Safari, and Firefox fully support ESM, so you should not have any problem running it in modern browsers.
Read more >JavaScript modules (ESM) now supported by major browsers
JavaScript modules (ESM) now supported by major browsers ... Using ECMAScript modules from ES6 / ES2015 has been a daily for many developers...
Read more >Life with ESM | CSS-Tricks
ESM, meaning ES Modules, meaning JavaScript Modules. Like, import and friends. Browsers support it these days. There is plenty of nuance, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for bringing this to our attention. We want to add support for ESM, but I don’t have a date for when that will get added. Please continue to upvote if this is something that you want.
That is a very significant ask =/
That being said, we’re not super happy with the state of mqtt-js at the moment. Haven’t seen a reasonable alternative yet. Preliminary discussions about implementing a pure-JS client ourselves but that’s a lot of time for uncertain payoff.