Error: Cannot find module 'web3' in node console.
const Web3 = require('web3');
Thrown:
{ Error: Cannot find module 'web3'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:613:15)
at Function.Module._load (internal/modules/cjs/loader.js:539:25)
at Module.require (internal/modules/cjs/loader.js:667:17)
at require (internal/modules/cjs/helpers.js:20:18) code: 'MODULE_NOT_FOUND' }
mkdir test
cd test
npm init
npm install web3
(also tried npm install ethereum/web3.js )
node
const Web3 = require("web3");
ls outputs node_modules/, package.json
and this node_modules directory has web3.
[email protected]v11.10.1Thanks for creating this support question! The described behavior is working in my environment and it looks like a support problem. Could you add a URL to a GitHub repository for having a bit more context?
Thanks for the reply!
But now I got it working I just did npm install --save web3. I don't know why or how but it somehow worked and now I can use web3 on my linux machine.
Im having the same exact problem but cannot fix it using --save web3 just that when I do it in a new folder like you said it does work. But in the project I am working on it doesnt.
This is my package.json
{
"name": "agent",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"dev": "lite-server"
},
"author": "",
"license": "ISC",
"dependencies": {
"solc": "^0.4.24",
"web3": "github:ethereum/web3.js"
},
"devDependencies": {
"lite-server": "^2.3.0"
}
}
And this is the error
Error: Cannot find module '/Users/pablo/Downloads/blockchain-for-healthcare-master/node_modules/web3/packages/web3/src/index.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (internal/modules/cjs/loader.js:292:19)
at Function.Module._findPath (internal/modules/cjs/loader.js:523:18)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:767:27)
at Function.Module._load (internal/modules/cjs/loader.js:685:27)
at Module.require (internal/modules/cjs/loader.js:838:19)
at require (internal/modules/cjs/helpers.js:74:18) {
code: 'MODULE_NOT_FOUND',
path: '/Users/pablo/Downloads/blockchain-for-healthcare-master/node_modules/web3/package.json',
requestPath: 'web3'
I have the same problem with Create React App:
yarn add web3
```js
import Web3 from 'web3'
```bash
./node_modules/web3/src/index.js
Module not found: Can't resolve '/home/cs/work/argn/node_modules/babel-loader/lib/index.js' in '/home/cs/work/argn'
have the same issue and also try this solution but in vain. still getting error of web3 not defined
Most helpful comment
Thanks for the reply!
But now I got it working I just did
npm install --save web3. I don't know why or how but it somehow worked and now I can use web3 on my linux machine.