2

I'm importing bitcore-mnemonic in my React project with this conditions:

  • I'm importing it just once and in one file.
  • The component utilising it is imported just once and is called by react-router.
  • No other library is using bitcore-lib. How did I find? searched node_modules.
  • I'm importing as import mnemonic from 'bitcore-mnemonic';.

And I'm getting this error while running unit tests:

Uncaught 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.

Please help me know what I'm doing wrong.

Reyraa
  • 4,174
  • 2
  • 28
  • 54

1 Answers1

1

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:

if (global._bitcore) delete global._bitcore;
const mnemonic = require('bitcore-mnemonic');
  • Remember you can not use import instead of require(Hoisting).
  • If you're using webpack, it takes care of multiple import/require statements.
Reyraa
  • 4,174
  • 2
  • 28
  • 54