Skip to content

Fix ESM bundle missing named exports#2034

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-export-connect-function
Draft

Fix ESM bundle missing named exports#2034
Copilot wants to merge 3 commits intomainfrom
copilot/fix-export-connect-function

Conversation

Copy link
Copy Markdown

Copilot AI commented Jan 13, 2026

The ESM bundle (dist/mqtt.esm.js) was not exporting named exports like connect, connectAsync, etc., causing import errors in browser environments using ES modules.

Root cause: esbuild was bundling a CommonJS entry point for ESM output. When bundling CJS modules with export * re-exports, esbuild cannot convert module.exports to ES6 export statements.

Changes:

  • Created src/index.esm.ts: Dedicated ESM entry point using native ES6 export syntax

    export { default } from './mqtt'
    export { connect, connectAsync, MqttClient, Client, ... } from './mqtt'
    export * from './mqtt'
  • Updated esbuild.js: ESM bundle now uses build/index.esm.js instead of build/index.js

  • Enhanced src/index.ts: Added explicit named re-exports for improved CommonJS compatibility

The generated ESM bundle now properly exports all named exports while maintaining backward compatibility.

Example usage:

import { connect } from 'mqtt'  // Now works in ESM environments
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: 5.14.0does not provide an export named 'connect'</issue_title>
<issue_description>### MQTTjs Version

5.14.0

Broker

暂不详

Environment

Browser

Description

Image

Minimal Reproduction

does not provide an export named 'connect'

Debug logs

does not provide an export named 'connect'</issue_description>

<agent_instructions>Fix issue browser bundle not exporting connect function like nodejs </agent_instructions>

Comments on the Issue (you are @copilot in this section)

@robertsLando @xuzhongfei how are you importing mqtt? Does previous version works?

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 13, 2026 16:15
Co-authored-by: robertsLando <11502495+robertsLando@users.noreply.github.com>
Co-authored-by: robertsLando <11502495+robertsLando@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix browser bundle not exporting connect function Fix ESM bundle missing named exports Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 5.14.0does not provide an export named 'connect'

2 participants