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

rollup, es6 support? #479

Closed
aedart opened this issue Oct 26, 2016 · 9 comments
Closed

rollup, es6 support? #479

aedart opened this issue Oct 26, 2016 · 9 comments

Comments

@aedart
Copy link

aedart commented Oct 26, 2016

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?

@mcollina
Copy link
Member

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.

@aedart
Copy link
Author

aedart commented Oct 26, 2016

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 rollup/rollup-plugin-commonjs#134 for further info.

Anyways, ty for your reply.

@mcollina
Copy link
Member

closing this now. Feel free to open issues if it turns out it's MQTT.js fault.

@lesquirrel23
Copy link

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.

@Crisfole
Copy link

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.

@idbartosz
Copy link

idbartosz commented Jun 19, 2020

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 😉

@kcdipesh
Copy link

Did anyone manage to successfully import using rollup or es6 import syntax?

@chartinger
Copy link

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)

@psi-4ward
Copy link

seems mqttjs targets only node and not the browser

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

8 participants