-
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 v5 Feedbacks #1639
Comments
Hey @robertsLando may I show you my approach how to resolve the
Also if there are other/better solutions, I am curious to see them. |
That's exactly what rollup polifilly module does |
useful for me ,mqtt5.0.2 vite4.3.9 |
when i yarn build, This resulted in an error:, it seemlike this code in vite.coinfig.ts: |
Hello, I successfully used mqtt for the Yarn dev project after using the vite.config.ts code you provided. However, the project will report an error after Yarn build And deploy it to run on the server, so I git clone your project and install example project(Folder vite-example). unfortunate, npm run dev succeeded, but npm run build failed after deploy it to run on the server error Code: UR.default.parse is not a functionat Object.Up [as connect] |
Try adding the url polifilly: import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill";
import { NodeModulesPolyfillPlugin } from "@esbuild-plugins/node-modules-polyfill";
import nodePolyfills from "rollup-plugin-polyfill-node";
export default defineConfig({
// Other rules...
resolve: {
alias: {
url: "rollup-plugin-node-polyfills/polyfills/url", <-------- THIS
util: "rollup-plugin-node-polyfills/polyfills/util",
querystring: "rollup-plugin-node-polyfills/polyfills/qs",
},
},
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: "globalThis",
},
// Enable esbuild polyfill plugins
plugins: [
NodeGlobalsPolyfillPlugin({
buffer: true,
}),
NodeModulesPolyfillPlugin(),
],
},
},
build: {
rollupOptions: {
// Enable rollup polyfills plugin
// used during production bundling
plugins: [nodePolyfills()],
},
},
}); |
@robertsLando Hello! I have a request for the This method cannot work in MQTT.js v5 but works in MQTT.js v4.3.7. In MQTT.js v5 the error is Then I add I don't want to install Please correct me if I am wrong. Thanks for reading! |
@vagreargnatry would you like to submit a PR please? |
You also need to pay attention to the browser environment: |
For anyone using mqttjs in browser, just use import * as mqtt from 'mqtt/dist/mqtt' there is no need of any configuration both in vite/webpack then |
Thank you @robertsLando for the instruction. I just want to report my findings: DOESN'T WORK:
WORKS:
|
@function1983 Remove the |
My thought was exactly the same. But in reality I still do need polyfilling as mentioned in your vite config.
Other than that quirk, mqttjs runs flawlessly and very stable for me. |
There must be something else that requires them because in my example I'm able to run it and build too without any polifilly, the |
I have just upgrade to In Was it moved somewhere else? Was it removed? Does it still needs to be implemented? 🤔 🙏 |
@tukusejssirs |
@robertsLando, I have installed I import and use it like tgis: import {connect} from 'mqtt'
const client = connect(options)
client.setMaxListeners(number) // This fails |
Ok this seems an issue, I will fix it asap. In the meanwhile I suggest to try this: // @ts-expect-error
client.setMaxListeners(number) When you will install a version of mqttjs that fixes that the ts compiler will warn you that the |
@tukusejssirs 5.1.3 fixes your issue |
I'm closing this as now mqtt v5 is out |
FYI starting from 5.2.1 you can now import mqtt in browser using:
|
Use this issue to report your feedback about MQTTv5 version. Positive feedbacks are welcome too so we know everything is working as expected 😄
The text was updated successfully, but these errors were encountered: