truffle – Solving ‘Couldn’t Find Module ethereumjs-wallet/hdkey’ Error

blockchainethereum-classicethereumjsnodejstruffle

I was running this code deploy.js

const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { interface, bytecode } = require('./compile');

const provider = new HDWalletProvider(
    '***** ****** ********* ********************* ***********',
    'https://rinkeby.infura.io/v3/*****************'
);

const web3 = new Web3(provider);

const deploy = async () => {
  const accounts = await web3.eth.getAccounts();

  console.log('Attempting to deploy from account', accounts[0]);

  const result = await new web3.eth.Contract(JSON.parse(interface))
    .deploy({ data: bytecode, arguments: ['Hi there!'] })
    .send({ gas: '1000000', from: accounts[0] });

  console.log('Contract deployed to', result.options.address);
};
deploy();

and I got this below given out.

node deploy.js
module.js:549
    throw err;
    ^

Error: Cannot find module 'ethereumjs-wallet/hdkey'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\Saurabh\inbox\node_modules\truffle-hdwallet-provider\index.js:2:13)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

I am pretty sure that I have not done any typo. This some packaging issue. Does anyone have the idea how to resolve?

Best Answer

Update: npm uninstall ethereumjs-wallet npm uninstall truffle-hdwallet-provider npm install --save ethereumjs-wallet@0.6.0 npm install --save truffle-hdwallet-provider@0.0.3

Credit goes to 2 gentlemen on udemy QA Sarshad and Guang


I tried to install a prior version to ethereumjs-wallet (npm install --save ethereumjs-wallet@0.5.2 or @0.6.0) and this time it starts running but crashes on the async/await as a warning.

No transaction either on etherscan so it seems need to use promises with prior versions < 0.6.1 of ethereumjs-wallet (haven't tried that yet).

ethereumjs-wallet@0.6.1 has a different file structure and hdkey is no longer in its root folder.