aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.44k stars 2.13k forks source link

fix(pubsub): fix ESM compatibility issue #14014

Open kyle-seongwoo-jun opened 6 days ago

kyle-seongwoo-jun commented 6 days ago

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 that paho-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 use Paho.Client without any compatibility issues.

Issue #, if available

Description of how you validated changes

  1. Imported the updated package into an ESM project.
  2. Verified that the Paho.Client is not a constructor error no longer occurs during runtime.
  3. Tested the MQTT connection functionality to ensure it works as expected with the MqttOverWS implementation.
  4. Confirmed that the Rollup build process completes without errors and generates correct ESM-compatible output.

Checklist

Checklist for repo maintainers

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.