-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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.js does not work with Webpack 5.x #1582
Comments
You can use the following workaround (tested to work with the latest react-scripts 5.0.1 used in create-react-app) when using Webpack
|
|
The alternative to the answer of @viliket would be to load the polyfills via
|
cannot read properties of undefined (reading 'Buffer') |
Please consider opening a PR to fix this issue |
MQTT 5.0.0 BETA is now available! Try it out and give us feedback: |
@robertsLando I get a:
|
@Nosferatu31 https://stackoverflow.com/questions/41359504/webpack-bundle-js-uncaught-referenceerror-process-is-not-defined ? Also instead of importing mqtt module you could try importing the minified version: |
Since I am using CRA, I did not want to eject it to configure the Webpack configuration file... |
CRA is de facto not maintaned anymore. See for context, the React documentation removed CRA as it is not longer recommended to start a react project this way and some reasoning behind this to read here reactjs/react.dev#5487 (comment) If you are keen to move to a similar setup I can recommend the React Vite template. Depending on how big your project is the switch can be pretty straightforward. And there you just configure the vite config. But if you want to stay with CRA and do not want to eject, I am not sure if there is a solution. (my guess is no) |
I have fixed Browser docs by adding webpack and vite setup. Check them out |
FYI starting from 5.2.1 you can now import mqtt in browser using:
|
@robertsLando I think that my issue with CRA was solved with 5.2.1, thank you! |
Webpack 5.x removed the Nodejs polyfills (see facebook/create-react-app#12072), including
Buffer
. Since MQTTjs depends onmqtt-packets
which usesBuffer
it cannot be used with Webpack 5.x following the instructions provided in the doc.Please fix removing dependency on Buffer to make the library compatible with Webpack 5.x without requiring polyfills, or update the documentation accordingly.
The text was updated successfully, but these errors were encountered: