Skip to content
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

mqtt / nuxt 3 - Uncaught ReferenceError #81

Closed
briankandersen opened this issue Apr 20, 2023 · 2 comments
Closed

mqtt / nuxt 3 - Uncaught ReferenceError #81

briankandersen opened this issue Apr 20, 2023 · 2 comments
Assignees

Comments

@briankandersen
Copy link

As soon as I try to call the mqtt connect function, I get this error in the console:

Uncaught ReferenceError: Buffer is not defined
at node_modules/mqtt-packet/constants.js

Has anybody successfully gotten mqttjs to work in nuxt 3?

@0721Betty
Copy link
Member

0721Betty commented Apr 23, 2023

As soon as I try to call the mqtt connect function, I get this error in the console:

Uncaught ReferenceError: Buffer is not defined at node_modules/mqtt-packet/constants.js

Has anybody successfully gotten mqttjs to work in nuxt 3?

Hope the following code is useful to you

import * as mqtt from "mqtt/dist/mqtt.min";

if (process.client) {
  const client = mqtt.connect("ws://broker.emqx.io:8083/mqtt");
  console.log("mqtt client", client);
}

in addition, refer to the MQTT.js issue: mqttjs/MQTT.js#1269, you should do like this:
image

@briankandersen
Copy link
Author

Thank you Betty, that works perfectly :)

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

No branches or pull requests

2 participants