-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix(pubsub): fix ESM compatibility issue #14014
base: main
Are you sure you want to change the base?
Conversation
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 |
public async newClient({ | ||
url, | ||
clientId, | ||
}: MqttOptions): Promise<MqttClient | undefined> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this change is introducing MqttClient
interface to the public newClient
method. However the MqttClient
is not really compatible with PahoClient
, for example onMessageArrived
is missed from MqttClient
. This could be a breaking change.
We should build an adapter class to map the method to the interfaces we have currently as PahoClient
. This would solve the TSC compability test failure as well because the public interfaces in index.d.ts
would not have reference to the types exported from 3rd party dependency mqtt.js
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AllanZhengYP Thanks for the review! I thought MqttClient
was only used internally and didn’t realize it was getting exposed through a public method.
I’ll go ahead and make the changes as you suggested.
Hey @kyle-seongwoo-jun, we can take on from here if you have limited bandwidth to work on this PR. Let us know! |
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.