-
Notifications
You must be signed in to change notification settings - Fork 1k
Remove include guards #21
Comments
So this is why it was introduced: bitpay/bitcore#1164 But there should be a better way. I am trying to reproduce the error with this example: https://github.com/Levino/understand-instanceof Can someone help me reproduce it? Mentioning @fanatid |
Okay, now I get it. But then one should remove the "instanceOf" calls instead of introducing include guards. |
So in principle one just wants a sanity check there. Should one not be happy then? I agree that people could pass a very old implementation of a Publickey into a new version of bitcore. But maybe it is better to allow this, than to mess this much with the require part of everything. Edit: The error will be handled quietly in most cases, if I understand correctly. |
Another solution could be to make PublicKey (and so on) their own packages and require them with: var PublicKey = require('bitcore-publickey') Am I wrong? |
Mentioning this #4 |
If you have correct |
@fanatid Thank you for pointing this out. Very interesting. Here is a read on peerDependencies: https://nodejs.org/en/blog/npm/peer-dependencies/ So I understand that moving this line to "peerDependencies" should solve all problems: https://github.com/bitpay/bitcore-mnemonic/blob/master/package.json#L41 Include guards can stay, even though I would prefer a warning instead of an error. |
Yep, I think that should solve problem. |
Just tested it. Requiring this version of bitcore-message and bitcore 0.13.6 in one application gives a nice error.
So please @braydonf and team, update the plugins, use peer dependencies and stop using include guards. |
I would really appreciate this, because I'm finding it difficult to develop locally using |
@paulkernfeld I agree totally. It is very un-npm-style to even think of introducing them. Really bad style. Take this fork if you want only warnings and not exceptions https://github.com/satoshipay/bitcore-lib |
@levino thanks! I think your link is broken; isn't that the main bitcore-lib repository? |
I believe that @levino is referring satoshipay/bitcore-lib, which changes this to a warning. Unfortunately, this doesn't fix my problem, because a dependency that I don't control (webcoin) still depends on the original version of bitcore-lib. :( To the bitcore team: what would it take to fix this? Would removing the instanceof calls be enough? |
In the mean time, here is a fun and sketchy workaround for anyone who is interested! I probably don't need to say that this is not the ideal solution. // Workaround for https://github.com/bitpay/bitcore-lib/issues/21
global._bitcore = undefined
var Script = require('bitcore-lib').Script
var Transaction = require('bitcore-lib').Transaction
global._bitcore = undefined |
@paulkernfeld Yes, sorry, took the wrong one. I corrected the link in my comment above. Deleting the include guards works also. See also here: bitpay/bitcore#1188 (comment) |
+1 @braydonf |
no, it is not. Because Bitcore-lib use If you run into the error, you can fix it doing the following: 1- Check were your ware including bitcore-lib: In the root of you project run: 2- You must have 2 or more results. In order to fix the error you need to have only one result. 3- Leave only one, and remove the others, but deleting the directly and adding a symlink to the one you left. That should fix the error. I understand it is a bit frustrating and probably there are better ways to solve this in the code, but this procedure should work on all cases. |
Maybe one should not check for "instance of"? I would say this is very very bad practice. It might be something that works in C++, Go or wherever stuff is type safe. But in JavaScript you just "try your best" with whatever you get. And if some dumb user gives you an object that does not fit the requirements, it is his bad. BOOOM exception. The checks you are mentioning have to ALSO be removed of course. |
Considering that |
Aha. This is helpful @braydonf But then is there not a better way? How exactly does the test help? |
Moved to: #67 |
…y/bitcore-lib#21, adding bitcore-lib as peerDependency
…y/bitcore-lib#21, adding bitcore-lib as peerDependency
…y/bitcore-lib#21, adding bitcore-lib as peerDependency
I cannot see why they are necessary. I do not find any global variables that need to be protected from being overwritten.
https://github.com/bitpay/bitcore-lib/blob/master/index.js#L7
The text was updated successfully, but these errors were encountered: