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

Error: More than one instance of bitcore-lib found. Please make sure to require bitcore-lib and check that submodules do not also include their own bitcore-lib dependency. #1454

Closed
xishoon opened this issue Jun 7, 2017 · 22 comments

Comments

@xishoon
Copy link

xishoon commented Jun 7, 2017

Hi everybody
When I run the command bitcored, it gives me the following error

/home/ruby/.nvm/versions/node/v4.8.3/lib/node_modules/bitcore/node_modules/insight-api/node_modules/bitcore-lib/index.js:12
throw new Error(message);
^
Error: More than one instance of bitcore-lib found. Please make sure to require bitcore-lib and check that submodules do not also include their own bitcore-lib dependency.
at Object.bitcore.versionGuard (/home/ruby/.nvm/versions/node/v4.8.3/lib/node_modules/bitcore/node_modules/insight-api/node_modules/bitcore-lib/index.js:12:11)
at Object. (/home/ruby/.nvm/versions/node/v4.8.3/lib/node_modules/bitcore/node_modules/insight-api/node_modules/bitcore-lib/index.js:15:9)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object. (/home/ruby/.nvm/versions/node/v4.8.3/lib/node_modules/bitcore/node_modules/insight-api/lib/blocks.js:4:15)
at Module._compile (module.js:409:26)

@anduck
Copy link

anduck commented Jun 7, 2017

Well, this is far from a proper way to solve this issue, but you can get rid of this error by editing file

~/.nvm/versions/node/v4.8.3/lib/node_modules/bitcore/node_modules/insight-api/node_modules/bitcore-lib/index.js

line 7:
bitcore.versionGuard = function(version) {
Change it to:
bitcore.versionGuard = function(version) { return;

I did this and so far no problems.

@rahulanand90
Copy link

I just went to index.js and I changed the line throw new Error(message) to throw new Error(version) in the file index.js. That gave me the current version of the bitcoin-lib. In my case, it was v0.13.19. Now revert the changes and updated the version to this one which you have got.

@Boyarov
Copy link

Boyarov commented Aug 11, 2017

this problem with npm version
enter:

nvm use v4
bitcored

@Lohann
Copy link

Lohann commented Nov 5, 2017

It works, thanks @Boyarov !

@adamu
Copy link

adamu commented Nov 7, 2017

This is the result of npm list from ~/.nvm/versions/node/v4.8.5/lib after installing bitcore:

├─┬ bitcore@4.1.1
│ ├─┬ bitcore-lib@0.14.0        <-- 0.14
│ │ ├── bn.js@2.0.4
│ │ ├── bs58@2.0.0
│ │ ├── buffer-compare@1.0.0
│ │ ├─┬ elliptic@3.0.3
│ │ │ ├── brorand@1.0.5
│ │ │ └── hash.js@1.0.3
│ │ ├── inherits@2.0.1
│ │ └── lodash@3.10.1
│ ├─┬ bitcore-node@3.1.3
│ │ ├── async@1.5.2
│ │ ├── bitcoind-rpc@0.6.0
│ │ ├─┬ bitcore-lib@0.13.19     <-- 0.13

It looks like bitcore depends on bitcore-lib v0.14, but then also depends on bitcore-node which depends on bitcore-lib v0.13, and then includes check to make sure there are not multiple versions of bitcore-lib.

Update: looks like it was broken here: ad4e25e, so the fix is to install the version before that, as @xibxor pointed out:

npm -g install bitcore@4.1.0

@usab
Copy link

usab commented Dec 12, 2017

@adamu
Is 4.1.0 the latest version? (edit: ok, its not ...)

@flotwig
Copy link

flotwig commented Feb 6, 2018

Would like to note that this issue is still present when installing bitcored from npm on a vanilla Ubuntu 17.10 installation.

@adubinsky
Copy link

npm -g install bitcore@4.1.0 fixed the issue for me.

@manojvenkateswararaja
Copy link

How to achieve assymetric encrypt and decrypt technique in ethereum by picking the keys from testrpc . In Testrpc iam getting account address and private key where the public key resides and how we need to pick it up.
"my code is"
var testIdentity= {
type: 'ethereum',
display: '0x54dbb737eac5007103e729e9ab7ce64a6850a310',
privateKey: '52435b1ff11b894da15d87399011841d5edec2de4552fdc29c8299574436924d',
publicKey: 'a35813f8025a217675e4f85e758d0a43616fe661',
foreign: false
};
var message = "foobar";
var bitcore = require('bitcore-lib');
var ECIES = require('bitcore-ecies');

                /**
             * encrypt the message with the publicKey of identity
             * @param  {{privateKey: ?string, publicKey: string}} identity
             * @param  {string} message
             */
            var encrypt = function(identity, message) {
        
                /*
                 * this key is used as false sample, because bitcore would crash when alice has no privateKey
                 */
                var privKey = new bitcore.PrivateKey('52435b1ff21b894da15d87399011841d5edec2de4552fdc29c8299574436925d');
                var alice = ECIES().privateKey(privKey).publicKey(new bitcore.PublicKey(identity.publicKey));
                var encrypted = alice.encrypt(message);
        
                return encrypted.toString('hex');
            };
        
            /**
             * decrypt the message with the privateKey of identity
             * @param  {{privateKey: ?string, publicKey: string}}   identity
             * @param  {string}   encrypted
             */
           
            
            
            
        var enc = encrypt(testIdentity, message);
        console.log("encrypted data...",enc)
        // var dec = decrypt(testIdentity, enc);
        
        // if(dec!="message"){
        //     alert('error');
        // }else{
        //     alert('sucess');
        // }
        
         var decrypt = function(identity, encrypted) {
                var privKey = new bitcore.PrivateKey(identity.privateKey);
                var alice = ECIES().privateKey(privKey);
        
                var decryptMe = new Buffer(encrypted.e, 'hex');
        
                var decrypted = alice.decrypt(decryptMe);
                return decrypted.toString('ascii');
            };
        
           var dec = decrypt(testIdentity, enc);
           console.log("decrypted file.....",dec)
     })

@xishoon xishoon closed this as completed Jul 12, 2018
@li069025
Copy link

@okwme
Copy link

okwme commented Feb 1, 2019

this error still occurs
@anduck solution still works but it's a lil nasty

@ameensol
Copy link

can confirm, just got this error

@adiingit
Copy link

Solution finally !!

#1457 (comment)

@trinisofttechnologies
Copy link

var bitcore = require('bitcore-explorers/node_modules/bitcore-lib');

You can use this to resolve this error.
Thanks

@34r7h
Copy link

34r7h commented Aug 7, 2019

the above solution is difficult using webpack and babel. is there a package that combines packages for simplicity?

@dchambers
Copy link

Adding this to my package.json did it for me:

"resolutions": {
  "bitcore-lib": "0.16.0"
}

@anubnair
Copy link

anubnair commented Nov 4, 2019

this issue is still persist. Say some package, for exampe Ethereum-Bip44, that has a dependency of bitcore 0.13.13. so the entire code should use 0.13.13 which is very old!

@placecodex
Copy link

placecodex commented Nov 23, 2020

my solution

enter in node_modules\bitcore-insight\node_modules

and delete bitcore-lib later npm install bitcore-lib and use it const bitcore = require('bitcore-lib');

@Chibueze-Adeyemi-Ajayi
Copy link

@trinisofttechnologies really worked for me too ... nice job, let keep building

@li069025
Copy link

li069025 commented Jun 19, 2022 via email

@PiusLucky
Copy link

PiusLucky commented Sep 26, 2023

Hope it helps.

import bitcore from 'bitcore-lib';
if (global._bitcore) delete global._bitcore;
const Insight = require('bitcore-insight').Insight;

let insight = new Insight('testnet');
console.log('🚀 ~ ', insight);
console.log('🚀 ~ ', bitcore);

bitcore-lib creates a global object named _bitcore, and every time you want to create an instance it checks to make sure that object is not available. To solve this, I simply delete this variable before requiring:

@estevanpedro
Copy link

Solved by creating a file lib/customBitcore.ts

const bitcore = require("bitcore-lib")

bitcore.versionGuard = () => {}

module.exports = bitcore

And edited the file next.config.mjs

/** @type {import('next').NextConfig} */
const nextConfig = {
  /** YOUR CONFIGS ... */
  webpack(config) {
    config.resolve.alias = {
      ...config.resolve.alias,
      "bitcore-lib": path.resolve(__dirname, "lib/customBitcore.ts"),
    }
    return config
  }
}

export default nextConfig

Basically replaces the function that was giving the throw new Error(message);.

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