1

I use nodejs to execute a javascript that interacts with my local instance of Ganache. I would like to use the web3-eth-debug module to get information about my transactions. However after installing the module with npm i web3-eth-debug or npm i -g web3-eth-debug and running the following Javascript code I get the error TypeError: Debug is not a constructor.

My code:

const Web3 = require('web3')
const fs = require('fs');
const Debug = require('web3-eth-debug')
const options = {
    transactionConfirmationBlocks: 1,
}
const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:7545"), null, options);
const debug = new Debug(new Web3.providers.HttpProvider("http://localhost:7545"), null, options);
...

Is the debug module supposed to be imported or constructed differently? What am I missing?

5
  • Perhaps you should import it exactly as shown in that link that you provided - import {Debug} from 'web3-eth-debug';. – goodvibration May 24 '19 at 7:17
  • Which implies to me that you can achieve the same with const Debug = require('web3-eth-debug').Debug. – goodvibration May 24 '19 at 7:18
  • I believe that the debug module exports an object (i.e., something like module.exports = {...}), in contrast with the web3 module, which exports a class. – goodvibration May 24 '19 at 7:19
  • And I'm saying all of this just by reading the example from the docs that you've linked here. – goodvibration May 24 '19 at 7:20
  • Thanks that solved it for me! If you would like to post it as an answer I'll confirm it. nodejs doesn't allow the import {Debug} from 'web3-eth-debug'; notation and I didn't realise this was how to do it. – Stefan May 24 '19 at 7:21
1

The coding example in the link that you provided shows:

import {Debug} from 'web3-eth-debug';

Which implies that you should do something like:

const Debug = require('web3-eth-debug').Debug

When comparing the two import statements in the coding example:

import Web3 from 'web3';
import {Debug} from 'web3-eth-debug';

I conclude that while the Web3 module exports a class (i.e., something like module.exports = class ...), the Debug module exports an object (i.e., something like module.exports = {...}).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.