Closed aedart closed 7 years ago
As far as I understand, this questions revolves around ES6 modules, and not other ES6 features. If this is not the case, please explain.
MQTT.js will be based on ES6 modules when it could run on top of any supported version of Node without a transpilation step. Currently this number is zero, so it will probably take a few lts cycles to get there.
Anyway, I am very happy of accepting any PRs that would make the integration with rollup easy, as long as it keeps running with no transpilation step on all supported versions of Node.
It would be good to see if we can work a reference on how to achieve this. Maybe rollup supports some metadata.
I wish that I had a good solution, but at the moment, I'm not even able to run a single connect test, because of commonjs' failure to resolve nested dependencies. I have no idea why, and therefore "fishing" for help anywhere I can...
See https://github.com/rollup/rollup-plugin-commonjs/issues/134 for further info.
Anyways, ty for your reply.
closing this now. Feel free to open issues if it turns out it's MQTT.js fault.
I use polymer - based on the current pwa starter kit - and want to integrate mqttjs. As far as i understand (sry, newby in js) with polymer in the default way i'm only able to integrate es6 modules.
Is there any plan to support es6 module import or is the answer above still valid? Thanks.
Bump. This is definitely problematic. Even with rollup-plugin-commonjs
installed we can't import the thing. Building with rollup and including es6 and common js distributions is the way to go these days.
I've tried with rollup-plugin-node-builtins and rollup-plugin-node-globals and it's imported but probably due to circular dependencies the connect
function throws:
[Rollup 2.17.0] compile warning:
(!) Circular dependencies
node_modules/readable-stream/lib/_stream_readable.js -> node_modules/readable-stream/lib/_stream_duplex.js -> node_modules/readable-stream/lib/_stream_readable.js
node_modules/readable-stream/lib/_stream_duplex.js -> node_modules/readable-stream/lib/_stream_writable.js -> node_modules/readable-stream/lib/_stream_duplex.js
node_modules/readable-stream/lib/_stream_duplex.js -> node_modules/readable-stream/lib/_stream_writable.js -> /Users/bartoszk/Projects/mqtt-dashboard/node_modules/readable-stream/lib/_stream_duplex.js?commonjs-proxy -> node_modules/readable-stream/lib/_stream_duplex.js
...and 3 more
[Chrome 83.0.4103.106] calling mqtt.client
_stream_duplex.js:77 Uncaught (in promise) TypeError: this.once is not a function
at BufferList$1.Duplex$1 (_stream_duplex.js:77)
at new BufferList$1 (bl.js:33)
at BufferList$1 (bl.js:8)
at Parser._resetState (parser.js:31)
at new Parser (parser.js:22)
at Object.Parser [as parser] (parser.js:11)
at MqttClient._setupStream (client.js:289)
at new MqttClient (client.js:276)
at Function.connect$1 [as connect] (index.js:154)
Conclusion:
So in the end to use it in Rollup we have to compile it with Webpack or import via script tag and then in rollup.config
set it up as external: ["mqtt"]
and output.globals: { mqtt: "mqtt" }
. This way everything works but I'd prefer to have it compiled during my build instead of external dependency 😉
Did anyone manage to successfully import using rollup or es6 import syntax?
Ended up with the same workaround as @idbartosz - include the compiled file in script and declare the global var in typescript. Failed miserably trying to get it imported with rollbarjs (and therefor vite)
seems mqttjs targets only node and not the browser
At the moment, it is very difficult to get the mqtt module to work with rollup. Therefore, I am wondering when you are going to release this package as es6?