Closed raj-oeeai closed 9 months ago
could you please put together a reproduction for this issue, thank you
could you please put together a reproduction for this issue, thank you
npm install mqtt --save-dev
app/services/demo-service.js
import Service from '@ember/service';
import mqtt from 'mqtt';
export default class DemoService extends Service {
connect() {
try {
const url = 'ws://broker.emqx.io:8083/mqtt';
const mqttOptions = {
clean: true,
connectTimeout: 4000,
clientId: 'emqx_test',
username: 'emqx_test',
password: 'emqx_test',
};
this.client = mqtt.connect(url, mqttOptions);
} catch (error) {
console.log(error);
}
}
}
error:
webpack returned errors to ember-auto-import
at WebpackBundler (ember-auto-import-webpack)
-~- created here: -~-
at new Plugin (/Users/raj/Desktop/dev/auto-import/node_modules/ember-auto-import/node_modules/broccoli-plugin/dist/index.js:47:36)
at new WebpackBundler (/Users/raj/Desktop/dev/auto-import/node_modules/ember-auto-import/js/webpack.js:112:9)
at AutoImport.makeBundler (/Users/raj/Desktop/dev/auto-import/node_modules/ember-auto-import/js/auto-import.js:110:16)
at AutoImport.addTo (/Users/raj/Desktop/dev/auto-import/node_modules/ember-auto-import/js/auto-import.js:129:51)
at Class.postprocessTree (/Users/raj/Desktop/dev/auto-import/node_modules/ember-auto-import/js/index.js:49:55)
at /Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/utilities/addon-process-tree.js:6:25
at Array.reduce (<anonymous>)
at addonProcessTree (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/utilities/addon-process-tree.js:4:32)
at EmberApp.addonPostprocessTree (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/broccoli/ember-app.js:909:12)
at EmberApp.toTree (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/broccoli/ember-app.js:1732:17)
at appInstance.toTree (/Users/raj/Desktop/dev/auto-import/node_modules/@embroider/macros/src/ember-addon-main.js:58:39)
at module.exports (/Users/raj/Desktop/dev/auto-import/ember-cli-build.js:23:14)
at Builder.readBuildFile (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/models/builder.js:49:14)
at Builder.setupBroccoliBuilder (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/models/builder.js:63:22)
at new Builder (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/models/builder.js:29:10)
at ServeTask.run (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/tasks/serve.js:49:7)
at /Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/models/command.js:238:24
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Class.run (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/commands/serve.js:106:5)
at async /Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/cli/cli.js:204:32
at async CLI.run (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/cli/cli.js:251:14)
at async module.exports (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/cli/index.js:145:12)
Error: webpack returned errors to ember-auto-import
at /Users/raj/Desktop/dev/auto-import/node_modules/ember-auto-import/js/webpack.js:537:32
at finalCallback (/Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:441:32)
at /Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:505:17
at /Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/HookWebpackError.js:68:3
at Hook.eval [as callAsync] (eval at create (/Users/raj/Desktop/dev/auto-import/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at Cache.storeBuildDependencies (/Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Cache.js:122:37)
at /Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:501:19
at Hook.eval [as callAsync] (eval at create (/Users/raj/Desktop/dev/auto-import/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at /Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:498:23
at Compiler.emitRecords (/Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:919:5)
at /Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:490:11
at /Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:885:14
at Hook.eval [as callAsync] (eval at create (/Users/raj/Desktop/dev/auto-import/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
at /Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:882:27
at /Users/raj/Desktop/dev/auto-import/node_modules/neo-async/async.js:2818:7
at done (/Users/raj/Desktop/dev/auto-import/node_modules/neo-async/async.js:3522:9)
at Hook.eval [as callAsync] (eval at create (/Users/raj/Desktop/dev/auto-import/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at /Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:736:33
at /Users/raj/Desktop/dev/auto-import/node_modules/graceful-fs/graceful-fs.js:143:16
at /Users/raj/Desktop/dev/auto-import/node_modules/graceful-fs/graceful-fs.js:61:14
at FSReqCallback.oncomplete (node:fs:191:23)
at new Plugin (/Users/raj/Desktop/dev/auto-import/node_modules/ember-auto-import/node_modules/broccoli-plugin/dist/index.js:47:36)
at new WebpackBundler (/Users/raj/Desktop/dev/auto-import/node_modules/ember-auto-import/js/webpack.js:112:9)
at AutoImport.makeBundler (/Users/raj/Desktop/dev/auto-import/node_modules/ember-auto-import/js/auto-import.js:110:16)
at AutoImport.addTo (/Users/raj/Desktop/dev/auto-import/node_modules/ember-auto-import/js/auto-import.js:129:51)
at Class.postprocessTree (/Users/raj/Desktop/dev/auto-import/node_modules/ember-auto-import/js/index.js:49:55)
at /Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/utilities/addon-process-tree.js:6:25
at Array.reduce (<anonymous>)
at addonProcessTree (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/utilities/addon-process-tree.js:4:32)
at EmberApp.addonPostprocessTree (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/broccoli/ember-app.js:909:12)
at EmberApp.toTree (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/broccoli/ember-app.js:1732:17)
at appInstance.toTree (/Users/raj/Desktop/dev/auto-import/node_modules/@embroider/macros/src/ember-addon-main.js:58:39)
at module.exports (/Users/raj/Desktop/dev/auto-import/ember-cli-build.js:23:14)
at Builder.readBuildFile (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/models/builder.js:49:14)
at Builder.setupBroccoliBuilder (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/models/builder.js:63:22)
at new Builder (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/models/builder.js:29:10)
at ServeTask.run (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/tasks/serve.js:49:7)
at /Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/models/command.js:238:24
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Class.run (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/commands/serve.js:106:5)
at async /Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/cli/cli.js:204:32
at async CLI.run (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/cli/cli.js:251:14)
at async module.exports (/Users/raj/Desktop/dev/auto-import/node_modules/ember-cli/lib/cli/index.js:145:12)
Error: webpack returned errors to ember-auto-import
at /Users/raj/Desktop/dev/auto-import/node_modules/ember-auto-import/js/webpack.js:537:32
at finalCallback (/Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:441:32)
at /Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:505:17
at /Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/HookWebpackError.js:68:3
at Hook.eval [as callAsync] (eval at create (/Users/raj/Desktop/dev/auto-import/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at Cache.storeBuildDependencies (/Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Cache.js:122:37)
at /Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:501:19
at Hook.eval [as callAsync] (eval at create (/Users/raj/Desktop/dev/auto-import/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at /Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:498:23
at Compiler.emitRecords (/Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:919:5)
at /Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:490:11
at /Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:885:14
at Hook.eval [as callAsync] (eval at create (/Users/raj/Desktop/dev/auto-import/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
at /Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:882:27
at /Users/raj/Desktop/dev/auto-import/node_modules/neo-async/async.js:2818:7
at done (/Users/raj/Desktop/dev/auto-import/node_modules/neo-async/async.js:3522:9)
at Hook.eval [as callAsync] (eval at create (/Users/raj/Desktop/dev/auto-import/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at /Users/raj/Desktop/dev/auto-import/node_modules/webpack/lib/Compiler.js:736:33
at /Users/raj/Desktop/dev/auto-import/node_modules/graceful-fs/graceful-fs.js:143:16
at /Users/raj/Desktop/dev/auto-import/node_modules/graceful-fs/graceful-fs.js:61:14
at FSReqCallback.oncomplete (node:fs:191:23)
Hey @void-mAlex Do you need more information for the reproduction?
mqtt has published a broken package. Its package.json says
"exports": {
".": {
"browser": {
"import": "./dist/mqtt.esm.js",
"default": "./dist/index.js"
},
},
"./dist/*": "./dist/*.js",
},
ember-auto-import consumes libraries via CJS, so it's the browser.default
that we're looking at. But the file dist/index.js
doesn't exist. It looks like they publish dist/mqtt.js
instead.
In this case you can workaround by importing mqtt/dist/mqtt
directly, since they do helpfully expose all of dist
.
Thanks, now the project at least builds. But I'm still encountering the following error:
TypeError: (0 , _mqtt.connectAsync) is not a function
Try their other dist files, probably the esm one would give you what you expected. I'm guessing the CJS one is being interpreted by the ESM/CJS interop as a single default export.
I found a solution for this issue, the folllowing steps helped me:
import * as mqttjs from "mqtt/dist/mqtt.esm";
const client = await mqttjs.default.connectAsync(mqttHost, mqttOptions, false);
const subscribed = await client.subscribeAsync(notificationTopic, { qos: 2 });
@raj-oeeai just ran into same issue upgrading deps, where my previously working esm import no longer works:
import { connectAsync } from 'mqtt';
The solution you posted works but not ideal.
Hi, I need some help with this Issue. I am trying to upgrade my ember project from 3.28 to 4.4. When I am using 'ember-auto-import' v2.7.1 and 'mqtt' v5.3.4 the project isn't building and throws this error:
I was using 'async-mqtt' v2.6.3 with 'ember-auto-import' v1.12.2 before switching to 'mqtt' v5.3.3 with 'ember-auto-import' v2.7.1 . When I use 'mqtt' v5.2.1 the project builds but throws an error that 'mqtt.connect' is not a function.
I tried to import with ' import mqtt from "mqtt"; ' & ' import mqtt* from "mqtt"; ' And i tried to import the connect component with ' import { connect } from "mqtt"; '