mqttjs / MQTT.js

The MQTT client for Node.js and the browser
Other
8.61k stars 1.42k forks source link

[Bug]: Import does not work properly with webpack > 5, ember-auto-import 2.X, browser and SSR (fastboot) #1934

Open hoIIer opened 2 months ago

hoIIer commented 2 months ago

MQTTjs Version

5.4.0

Broker

aws

Environment

NodeJS

Description

I'm in the process of upgrading an app that was previously using 5.0.3 and worked normally.

When using the latest mqtt 5.4.0, with webpack 5.94.0, ember 5.0.0, ember-auto-import 2.7.1, I see these issues:

Normal import no longer works (node/browser):

Previously worked:

import { connectAsync } from 'mqtt';

Now that results in connectAsync is not defined

Using strategy described here, I can get import to work in browser mode, but it fails in node as described below. (also this)

import mqtt from 'mqtt/dist/mqtt.esm';

 function() {
    ...
     connection = await mqtt.default.connectAsync(...)
}

Fastboot (node/ssr):

1) TypeError: Cannot set properties of undefined (setting 'AbortSignal')

TypeError: Cannot set properties of undefined (setting 'AbortSignal') at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:6:1347) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:5:1354) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:6:102193) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:5:1354) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:6:107827) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:5:1354) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:6:109301) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:5:1354) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:6:115088) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:5:1354) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:6:127946) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:5:1354) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:6:156523) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:5:1354) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:6:241329) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:5:1354) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:9:20193) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:5:1354) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:9:21547) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:5:1354) at eval (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:9:21647) at Module../node_modules/mqtt/dist/mqtt.esm.js (/var/folders/9r/gp7xyl_j0l3flcwp78j7mjcr0000gn/T/broccoli-77912wElEFjGOhfM7/out-464-broccoli_merge_trees/assets/chunk.vendors-node_modules_ember_test-helpers_dist_index_js-node_modules_faker-js_faker_dist_cjs_in-f33e59.7ed5976d6f429d809e98.js:33940:1) at __webpack_require__ (/var/folders/9r/gp7xyl_j0l3flcwp78j7mjcr0000gn/T/broccoli-77912wElEFjGOhfM7/out-464-broccoli_merge_trees/assets/chunk.app.38b6e5e110dec6f113ad.js:360:42)

2) ReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization

ReferenceError: Cannot access 'WEBPACK_DEFAULT_EXPORT' before initialization at Module.default (webpack://ember_auto_import/./node_modules/mqtt/dist/mqtt.esm.js?:3:42) at Module.makeDefaultExport (/var/folders/9r/gp7xyl_j0l3flcwp78j7mjcr0000gn/T/broccoli-77912wElEFjGOhfM7/out-464-broccoli_merge_trees/assets/vendor/loader/loader.js:87:1)

This is not ideal and I'd like to be able to do the regular import that previously worked with import { connectAsync } from 'mqtt'.

Any suggestions?

Thanks!

Minimal Reproduction

n/a

Debug logs

n/a