-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(pubsub): fix ESM compatibility issue #14014
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
Conversation
Added @rollup/plugin-commonjs to handle CommonJS modules in ESM build, ensuring compatibility with paho-mqtt.js.
Hi AWS Amplify Team(@HuiSF @cwomack), First, I want to thank you for all the hard work and dedication you’ve put into this project. Recently, I migrated my project to ESM and encountered this issue. As a workaround, I’ve been using patch-package to modify the After reviewing the code blame of the pubsub package, it seems that there have been issues with ESM support since its very first version. The root cause of this problem lies in the fact that the pubsub package uses
I’d love to hear your thoughts and see how these solutions align with your policies or long-term plans. My goal is to help in any way I can. Thank you for your time and consideration! |
Hey @kyle-seongwoo-jun, thanks for working on a fix for ESM and suggesting alternatives! After assessing the situation, I'm more inclined to go with replacing |
fa9d2b2
to
e947379
Compare
Hi @joon-won, I just force-pushed to the
Of course! I’d be happy to help anytime. Thanks! 🙌 |
Thanks @kyle-seongwoo-jun 👍 The team will now go through review process + add few more things with the PR. |
After checking the error from tsc-compliance-test, I found that the current I confirmed that downgrading the |
Thanks for exploring the options @kyle-seongwoo-jun, could also check |
Hey @kyle-seongwoo-jun, we can take on from here if you have limited bandwidth to work on this PR. Let us know! |
Hey @kyle-seongwoo-jun 👋 can you also share the repo or some code examples with us to reproduce the issue? |
Thank you for your time and work on this PR! Please let us know by opening a new issue if you find anything is not working or a feature request if there's any you'd love to see from Amplify 😄 |
Description of changes
This PR resolves the issue where using
paho-mqtt.js
in an ESM project caused the error:Paho.Client is not a constructor
. The root cause was thatpaho-mqtt.js
is distributed as a UMD module, which is incompatible with native ESM imports.To address this, the build process has been updated to include the @rollup/plugin-commonjs plugin. This plugin ensures that UMD modules like
paho-mqtt.js
are correctly transformed into ESM-compatible modules during the ESM build process.This change allows
MqttOverWS
to usePaho.Client
without any compatibility issues.Issue #, if available
Description of how you validated changes
Paho.Client is not a constructor
error no longer occurs during runtime.MqttOverWS
implementation.Checklist
yarn test
passesChecklist for repo maintainers
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.