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

Support using with ESM in browser #223

Closed
coderbyheart opened this issue Feb 23, 2022 · 9 comments
Closed

Support using with ESM in browser #223

coderbyheart opened this issue Feb 23, 2022 · 9 comments
Labels
feature-request A feature should be added or improved. p2 This is a standard priority issue

Comments

@coderbyheart
Copy link

coderbyheart commented Feb 23, 2022

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

@coderbyheart coderbyheart added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Feb 23, 2022
@jmklix
Copy link
Member

jmklix commented Mar 21, 2022

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.

@jmklix jmklix removed the needs-triage This issue or PR still needs to be triaged. label Mar 21, 2022
@matiasfha
Copy link

Maybe, monkey patch the dependency by using an alias inside webpack/vite configuration?

@bretambrose
Copy link
Contributor

Would it be accurate to say this is an issue with mqtt-js and not the SDK? What is under SDK/CRT control that can help address this?

@matiasfha
Copy link

The SDK can replace the dependency on non ESM packages like the mqtt one

@bretambrose
Copy link
Contributor

bretambrose commented Dec 15, 2022

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.

@coderbyheart
Copy link
Author

In the mean-time we have gotten proper Websocket API support on API Gateway which provides a better alternative for our use-case. So if you need real-time updates from your IoT devices, I encourage you to look into that instead.

@jmklix
Copy link
Member

jmklix commented May 12, 2023

As @bretambrose said, for ESM to work with this sdk it would need to work with mqtt-js. The changes need to be made in that repo. Because of this I'm going to close this feature request.

@jmklix jmklix closed this as not planned Won't fix, can't repro, duplicate, stale May 12, 2023
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@linglingsyu
Copy link

@jmklix mqtt.js seems to have been updated, see mqttjs/MQTT.js#1269
any modifications would be greatly appreciated , thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

5 participants