2

I am making a dapp and I am trying to import modules. The structure of my folders is the one that you can get from the truffle webpackage, the following:

-App
---build
---constracts
---migrations
---node_modules
-----ethereumjs-tx <--- module to import
---src
-----js
-------app.js <-------- App where I am calling the module
--test

I am writing:

const Tx = require('ethereumjs-tx');
const Tx = require('../../node_modules/ethereumjs-tx');
const Tx = require('{all my path}/ethereumjs-tx');

I also tried copying the module in my own directory

const Tx = require('/ethereumjs-tx');
const Tx = require('./ethereumjs-tx');

and changing const to var, but I always get the same error:

Cannot find module 'ethereumjs-tx'

Any idea how to solve that? or is there another way to use this module?

3

I am not sure how you installed ethereumjs-tx , but you can check that in your package.json file. If you don't see ethereumjs-tx there means your app is not using that module even if it is installed.

You can install it with :-

Run you cmd as administrator and navigate to folder where all files of project are there and run this command :-

npm install ethereumjs-tx --save

OR

open your code editor you are using and navigate to your project and run the same command . suppose i have all my files in blockchain folder :-

PS D:\Projects\blockchainNew\blockchain>npm install ethereumjs-tx --save

after this you only have to use --

var Tx = require('ethereumjs-tx');

also dont forget to check entry in package.json file

0

require doesn't work in this case. I had to import as script in my dapp ethereum-tx.js from ethereumjs - Browser Builds

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.