How to solve “Module not found: Error: Can't resolve 'truffle-contract'” error in web3?

+1 vote

I am trying to work on truffle-contract and web3 but I am facing problem when I execute the npm run dev command. The error is as follows:

ERROR in ./app/javascripts/app.js
Module not found: Error: Can't resolve 'truffle-contract' in 'C:\Users\edureka\Desktop\SID\ALSC\PROJECT\asset-lending\app\javascripts'
 @ ./app/javascripts/app.js 6:1-55
 @ multi (webpack)-dev-server/client?http://localhost:8080 ./app/javascripts/app.js

ERROR in ./app/javascripts/app.js
Module not found: Error: Can't resolve 'web3' in 'C:\Users\edureka\Desktop\SID\ALSC\PROJECT\asset-lending\app\javascripts'
 @ ./app/javascripts/app.js 5:1-39
 @ multi (webpack)-dev-server/client?http://localhost:8080 ./app/javascripts/app.js
webpack: Failed to compile.

How to solve this error?

Jul 26, 2018 in Blockchain by slayer
• 29,300 points
2,824 views

3 answers to this question.

+2 votes
Best answer

Try compiling and migrating the contract:

$ truffle compile
$ truffle migrate
answered Apr 30, 2019 by Rachita

selected Apr 30, 2019 by Omkar
+1 vote

Execute the following command:

$ npm install truffle-contract

It should solve your error. If it does not then try installing truffle-contract globally like this:

$ npm install -g truffle-contract

 To know more visit: https://www.npmjs.com/package/truffle-contract

answered Jul 26, 2018 by digger
• 26,680 points
+1 vote

Maybe there are missing necessary files. Try getting react.

$ truffle unbox react
answered Apr 30, 2019 by Jashn

Related Questions In Blockchain

+1 vote
5 answers

How to solve "truffle: command not found" error in blockchain?

First try restarting the system and then ...READ MORE

answered Jul 16, 2018 in Blockchain by slayer
• 29,300 points
3,525 views
0 votes
1 answer

Module not found: Can't resolve './truffle-contract/build/contracts

Hey! Firstly, there seems to be a ...READ MORE

answered May 9, 2019 in Blockchain by Omkar
• 69,030 points
637 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,810 points
438 views
0 votes
1 answer
0 votes
1 answer

How to manually create the instance of the contract in truffle?

You can try to do it like ...READ MORE

answered Sep 24, 2018 in Blockchain by slayer
• 29,300 points
534 views
0 votes
10 answers

How to solve gradle build failed error?

I migrated the project to a different ...READ MORE

answered Dec 7, 2018 in Blockchain by Rajat
19,618 views