-
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
Don't rely on node built-ins #804
Comments
@chrste90 I would really like if we could do so. Would you like to send to highlight the main offenders? Let me know if you plan to open a PR. |
@mcollina Oh, you are right, there are some more problematic dependencies. If i start an angular app, i get this error:
So i think the main problematic dependency is readable-stream (Or their dependency process-nextick-args). Do you know if it is possible to replace readable-stream with another dependency or should i try to bring up the error on their site? But if i look at their repo: https://github.com/nodejs/readable-stream, it looks like it is a library especially for node.js, so i don't think it would be approriate to change the use of node built-ins there. Also for this repo, i just searched for The uses of process.env in the tests should do no harm if one would try to use this lib in angular. But for bin/sub.js and bin/pub.js there are uses of process.exit(). Is this code used by consumers or only for examples in this repo (sorry, i'm not very familiar with mqtt.js yet :)) |
I don't think we can easily change the behavior in readable-stream, but we can specify a browser field in
These are executables for Node.js, it should stay as it is. |
Okay i don't exactly understand what you mean by this. Is it something that can be done in this repo or should it be changed in process-nexttick-args? Any other ideas what can be done with |
Ideally it should be replaced by the asap module that handles environment differences gracefully. |
We can't use that module because the behavior is different in Node.js. However, we can use the same technique that's in asap to not use |
Is it something you can do? I'm not very familiar with either one or the other, so it would be very hard for me do make the right changes and don't break anything in this lib. |
I've absolutely not bandwidth to do this. |
Okay, then i will need to find some time and make it working somehow. For the Readable-Streams: Do you think it can be possible to change to https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream or does the stream api behave differently than the readable-stream package which is used now? |
I also did some quick research and found out that the best alternative in browser for What about making a switch: In browser use
|
@mcollina any opinion about this? If you agree I would like to prepare a PR. |
@sclausen unfortunately it's not possible for two reasons. Firstly, promises wrap every function in a try-catch, changing how error would work. Secondly, Promise is not available in all the supported of readable-stream. The approach with |
Everything I tried doesn't work and it's not only |
Why can't you import a browserified version of mqtt.js? What did you use to create the browserify bundle? This sounds more like an angular-cli problem than an mqtt.js problem. |
@RangerMauve: I actually can import a javascript file and browserifying mqtt.js works like a charm, but the file doesn't get embedded in the bundle angular-cli (or ng-packagr) creates afterwards.
Yes, yes it totally is. angular-cli is an awesome project but such a major breaking change without any migration options is very... unpleasant. I totally understand why they decided to remove the node-shims, but without any other options to achieve such goals? Not nice. TL;DR I think we're done here. However we get to fix this issue with our library is nothing which has to be achieved in this project. |
Sorry to hear you got screwed over so hard! Do post any updates if you find a clever workaround! |
I think the best workaround is not switching to |
Hey am new to all this and I would like to use mqtt and I keep getting the Reference error |
The first thing you should do is reading this thread. Then you should understand what has been written and then you should know how to deal with the mentioned error. |
@sclausen Thanks for the quick response..but am totally new to nodejs and angular..can you give me some steps to follow or something |
You can browserify mqtt.js as described in the docs here, then you put the file in a folder of your angular project like that |
Thanks for the help... I used the "browserify'd" version of mqtt.js and It worked like a charm here is a link |
I'm trying to use mqtt.js in an angular v6 app.
The problem is that mqtt.js uses process which doesn't exist in a browser environment.
In older versions of angular the cli provided node-shims to get it working but as of v6 it doesn't do it anymore. See angular/angular-cli#9827 (comment) for more context.
It would be nice if mqtt.js wouldn't rely on node build-ins like process.
The text was updated successfully, but these errors were encountered: