-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
ReferenceError: Buffer is not defined ReactJS #1412
Comments
I have the same probelm as you, and have submitted a PR. |
@flyfishzy I see the PR is merged in mqtt-packet. is the problem in our dependency version in mqtt.js? |
@YoDaMa Yes, we need to upgrade the mqtt-packet version. But there are other similar problems, I'm trying to continue to fix them. |
Is there a workaround for this for time being? |
The release 4.3.6 still does not solve the issue for React. I am using react 17.0.2, react-scripts 5.0.0, and to build the MQTT js - webpack version 5.6.9. Also, I have tried downgrading the global version of webpack to 4.4, 4.6 - still getting the same error. |
Using a workaround for React js - Using Node js 14, Mqtt 4.0.1, react-scripts 4.0.3. This configuration build works even with the webpack latest version 5.6.9. |
This works for me |
Thank you, But I have tried it. Unable to set TLS certificates for SSL connection to a secure broker. |
I was able to build mqtt for React following these steps: inside of
|
I have similar problem for Ionic 6 Angular 13 app. I do not have webpack.config.js. |
if anyone here wants to offer a PR to fix this, it will be welcome. |
After crawling the web for 5 6 hours i didnt find any working solution you saved me man. God bless you |
This worked for me( ty ), I got error because there was no mqtt.browser.js file , instead there was "./dist/mqtt.js" so I configure package.json like "./mqtt.js": "./dist/mqtt.js" and at the end ./dist/mqtt.browser.js was created so I changed my package.json back to "./dist/mqtt.browser.js" and it worked. |
I would suggest to use this package instead No need to compile just install and use, Its a build version of mqtt@4.3.7. can be used with react and other frontend libraries |
Hey, I also have this issue. Does anyone have a solution that does not require webpack changes? |
This package is lacking type definitions and doesn't work well in typescript project. |
Hello you saved my PhD I love you thanks |
So if you're using MQTT for the web(mostly react). Your import should be like below import mqtt from "mqtt/dist/mqtt"; And if you're using typescript, you need to add the below in a global type's definition or create an declare module "mqtt/dist/mqtt" {
import MQTT from "mqtt"
export = MQTT
} remember to include the types file in |
Check the solution I just provided whether it works for you. Works for my team! |
Works perfectly ! Thanks ! |
I got the webpack technique to work but then it later broke. It's like they really don't want us to use mqtt in a browser so they don't fix it. I use |
👍🏻 Importing from
|
Thank you, you save me, I had a react app, that was using: |
Another quick hack, without any deep config changes. Just add this to your index.html:
|
checkout this solution need to install precompiled-mqtt which is a wrapper of mqtt base package where you don't need to perform bundle related extra works |
Could be fixed by #1571 |
MQTT 5.0.0 BETA is now available! Try it out and give us feedback: |
I have fixed Browser docs by adding webpack and vite setup. Check them out |
I have react app which is created by create-react-app and follow the rules that provides here
https://github.com/mqttjs/MQTT.js#react
But when I start my app I am getting following error
I have look around similar to this issue but it didn't help me.
I am using react version 17.0.2 and react-scripts version 5.0.0
I am gone through this issue
#1294
But it didn't help me because I don't have any webpack config file on my react app.
The text was updated successfully, but these errors were encountered: