web3 / web3.js

Collection of comprehensive TypeScript libraries for Interaction with the Ethereum JSON RPC API and utility functions.
https://web3js.org/
Other
19.18k stars 4.91k forks source link

Web3.js returns "Cannot find module 'web3-requestManager'" #966

Closed guidosegni closed 7 years ago

guidosegni commented 7 years ago

Using node 6.11.1 on a macosx

I installed web3 with the following command:

npm install web3

Then i launch this - apparently - simple node command:

Web3 = require('web3');

Well, it returns the following error:

module.js:471
    throw err;
    ^

Error: Cannot find module 'web3-requestManager'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/fremente/Dropbox/Influx Design/Web htdocs/ethereum/node_modules/web3/packages/web3-core/src/index.js:26:22)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

it looks like it require some module (e.g. 'web3-requestManager') that aren't installed with the package.

Any Idea? Am i doing something wrong?

Moejoe90 commented 7 years ago

I'm having the same issue apparently, when i try to install the needed file manually i get only an older version

jdkanani commented 7 years ago

I am having same issue. @frozeman

cowpig commented 7 years ago

having the same issue

frozeman commented 7 years ago

It was a package renaming issue, i fixed in the latest beat.15

jefflau commented 7 years ago

I just installed web3 today and I am also getting this issue. Is this already on npm?

Getting this error:

./~/web3/packages/web3-core/src/index.js
Module not found: Can't resolve 'web3-core-requestmanager' in '/Users/jefflau/Projects/dapps/meth-wallet/node_modules/web3/packages/web3-core/src'
jefflau commented 7 years ago

Not sure what happened but the error disappeared. Maybe have something to do with metamask? After that error disappeared i couldn't get it working in metamask, but it works in Mist fine

youfoundron commented 7 years ago

@jefflau any idea of what might have fixed it? Getting this issue when I install truffle-contract.

frozeman commented 7 years ago

I forgot to publish this module. i published it, so the issue should go away.

frozeman commented 7 years ago

Truffle is and should not using the latest web3.js 1.0 beta, as its -> beta :) @tcoulter you should definitely take look at it though :)

youfoundron commented 7 years ago

Looks like truffle-contract is looking for web3 internal packages by names no longer on the npm registry, I moved my web3 version from ^1.0.0-beta.17 to 1.0.0-beta.15, removed node_modules, and re-npm installed to fix.

frozeman commented 7 years ago

That doesn't sound like a fix, and like i wrote truffle is probably not working with web3.js 1.0.0 yet

jdkanani commented 7 years ago

@frozeman I am still getting this error.

jdkanani commented 7 years ago

I think I found the problem. Checkout: https://github.com/yarnpkg/yarn/issues/711

Yarn doesn't handle nested node_modules as npm does.

pcjose commented 7 years ago

I added this in the .bashrc

NODE_PATH=${HOME}/node_modules

and the problem was solved.

robert-zaremba commented 7 years ago

@pcjose this somehow a workaround. I would like to keep all modules in my project directory. I've tried with:

NODE_PATH=<absolute-path-to-project-root>/node_modules

And it doesn't work. I found the following hack: https://github.com/yarnpkg/yarn/issues/711#issuecomment-260050154

Is there any clean way to tell yarn to install / link all dependencies recursively?

tcoulter commented 7 years ago

@frozeman

Truffle is and should not using the latest web3.js 1.0 beta, as its -> beta :)

Just to clear up any issues here, we haven't switched to 1.0 yet (nothing we have should be using it now, or has in the past). But we will switch once released!

stefanhuber commented 7 years ago

Unfortunately, I have this problem with beta18. I tried to use web3 inside an ionic app. The following errors I get:

Cannot find module "web3-core-requestmanager"

Error: Cannot find module "web3-core-requestmanager"
    at webpackMissingModule (http://localhost:8100/build/vendor.js:116468:86)
    at Object.<anonymous> (http://localhost:8100/build/vendor.js:116468:187)
    at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30)
    at Object.module.exports.version (http://localhost:8100/build/vendor.js:116365:12)
    at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30)
    at Object.191 (http://localhost:8100/build/main.js:44:63)
    at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30)
    at Object.262 (http://localhost:8100/build/main.js:222:75)
    at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30)
    at Object.213 (http://localhost:8100/build/main.js:163:73)

What should I do?

jdkanani commented 7 years ago

@stefanhuber

Please use npm install --save web3 instead of yarn add web3 as workaround of this bug!

Now, for webpack to work:

const { lstatSync, readdirSync } = require('fs');
const { join } = require('path');

// is directory
const isDirectory = source => lstatSync(source).isDirectory();
// get directories
const getDirectories = source => readdirSync(source).map(name => join(source, name)).filter(isDirectory);

const web3Modules = getDirectories(`${__dirname}/node_modules/web3/packages`); // web3 node_modules
const nodeModules = [`${__dirname}/node_modules`];
nodeModules.push(...web3Modules.map(m => join(m, 'node_modules')));

// in webpack rules use
resolve: {
    modulesDirectories: nodeModules,
]
jdkanani commented 7 years ago

By the way, for webpack to work, this request https://github.com/ethereum/web3.js/pull/1006 needs to get merged too.

stefanhuber commented 7 years ago

thanks for your fast reply. I use npm and not yarn. It seems that my problem really has todo with webpack...

jdkanani commented 7 years ago

@stefanhuber Try adding extra module directories in webpack resolve as I mentioned above https://github.com/ethereum/web3.js/issues/966#issuecomment-324604175 and see if works?

stefanhuber commented 7 years ago

@jdkanani thank you for your solution. However I have no idea where I should add this script. Could you a little bit more specific on that?

jdkanani commented 7 years ago

@stefanhuber Add that script (or javascript equivalent) into your webpack.config.js. It just creates array with extra module paths to resolve imports for webpack.

nodeModules will have something like this:

[
'/Users/stefanhuber/...yourprojectpath.../node_modules',
'/Users/stefanhuber/...yourprojectpath.../node_modules/web3/packages',
'/Users/stefanhuber/...yourprojectpath.../node_modules/web3/packages/web3-core/node_modules',
'/Users/stefanhuber/...yourprojectpath.../node_modules/web3/packages/web3-core-requestmanager/node_modules',
.....
.....
]

Now you assign that array to your webpack rules (in js/jsx loader) in webpack.config file.

stefanhuber commented 7 years ago

@jdkanani ok I managed to organize this inside the webpack and it seems to work.

web3.version is 1.0.0-beta.18, however the object web3.eth.contract is undefined. is there a different api?

TypeError: window.web3.eth.contract is not a function
    at http://localhost:8100/build/main.js:71:44
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9967)
    at Object.onInvokeTask (http://localhost:8100/build/vendor.js:4499:37)
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9888)
    at r.runTask (http://localhost:8100/build/polyfills.js:3:5143)
    at invoke (http://localhost:8100/build/polyfills.js:3:10945)
    at n (http://localhost:8100/build/polyfills.js:2:28549)
cmditch commented 7 years ago

@stefanhuber web3.eth.Contract

varadarajana commented 7 years ago

I just added export NODE_PATH=path/yo/node modules and web3 gets loaded. THis is same as commented by @pcjose

bwheeler96 commented 6 years ago

Out of curiosity, why would beta software become the default download of NPM vs whatever the previous stable is?

eafelix commented 6 years ago

Someone still has this issue? It still appears in the last version "web3": "^1.0.0-beta2"

davesag commented 6 years ago

This just started happening to me this morning trying to start truffle develop.

Running web3 1.0.0-beta2 npm outdated reports the latest as being 1.0.0-beta.26

Now I'm confused as to which is actually the most recent. Either way I tried installing 1.0.0-beta.26 instead and I get the same error. Running Truffle 4.0.1

bwheeler96 commented 6 years ago

@davesag I've downgraded to web3.js 0.20.2

Bottom line: web3 is in fucking shambles. There are a billion versions of every method across a bunch of "beta" releases, the "beta" is the default from the npm registry, and the documentation is fragmented.

Use anything else if you can

icetique commented 6 years ago

To fix: Error: Cannot find module 'web3-requestManager'

Try installing specified, latest version. The problem seems to be that npm is confused what version is the latest and also not all dependencies work. When you run npm outdated and it seems like this:

Package           Current        Wanted         Latest  Location
web3          1.0.0-beta2   1.0.0-beta2  1.0.0-beta.26

It may not work. Your current version should match the latest version, so use: npm install web3@1.0.0-beta.26

Your npm outdated will show you that you don't have the wanted version: web3 1.0.0-beta.26 1.0.0-beta2 1.0.0-beta.26

But it works. I don't know why the people who package web3 didn't see there is clearly a problem. Maybe they know some workaround? It seems that node is stripping out the '6' at the end of the wanted version so if you run npm install web3 it install latest version of web3, but is considering it as '1.0.0-beta2' which does not resolve some dependencies.

Works for me, but I am not using truffle. Are you sure you are updating the web3 in the npm directory that truffle uses? Also, you may try uninstall web3 first and install specified version.

wildmolasses commented 6 years ago

FYI, I had this problem. Here's what caused the problem.

  1. upgraded node
  2. tried to start my project, ran into a scrypt compile error.
  3. did npm update

My web3 submodules were then deleted.

To bring them back, I removed and then reinstalled web3.

lsaether commented 6 years ago

This error still persists. As others have pointed out, NPM seems to be downloading web3@1.0.0-beta2 in place of web3@1.0.0-beta.2*.

In my case I'm trying to distribute a package that uses web3@1.0.0-beta.28 to users over NPM. The package will download the wrong web3 version anytime someone tries to install my package. It is unfortunate, but I am forced to downgrade to the stable version for now until a workaround is found...

cosminstefanxp commented 6 years ago

Same issue while trying to deploy a code that uses web3 to Firebase Functions. @frozeman, any updates?

srameshr commented 6 years ago

Stuck with this. npm install web3 installs 0.2 version. It does not even support promises. Fix this please. Its painful to trace a callback is not defined error from web3 till this thread to find out npm is not fetching 1.0.x version.

bent0b0x commented 6 years ago

Any chance this may be resolved soon? I am also stuck having to use an ugly workaround 😅 .

Thanks!

elijahmurray commented 6 years ago

Still appears to be happening…why is this closed? Tried everything in this thread with no luck.

vsdigitall commented 6 years ago

The same thing after npm update, web3 updates to web3@1.0.0-beta2 instead of current web3@1.0.0-beta30

However reinstalling helps:

npm r web3
npm i web3
daniyalzade commented 6 years ago

Resolved the web3-requestManager issue by pinning to 1.0.0-beta.29 version. Previously it was installing 1.0.0-beta.2.

shuji-koike commented 6 years ago

I came across a same problem after I did yarn upgrade. As @daniyalzade has mentioned above, "pinning" the version explicitly (without ^ or ~) in package.json could be a workaround.

  "dependencies": {
    "web3": "1.0.0-beta.31"
  }

Seems like the version 1.0.0-beta2 which not having a "dot" after beta is somehow confusing yarn to resolve the latest version.

roppa commented 6 years ago

I'm getting this in 1.0.0-beta.31, but it works with 1.0.0-beta.30

arashkiani commented 6 years ago

going back to 1.0.0-beta.30 didnt work for me, but removing ^ did

ondratra commented 6 years ago

I had same issue but changing to fixed old version didn't help. Then I realized I am using very new version of Ganache that itself depended on new Web3.js version, thus overriding my package.json Web3js version.

roschler commented 6 years ago

I had the exact same problem. I needed to retrieve the Web3.js package directly from the develop branch on GitHub to fix the following error that was being thrown when I tried to run the Node.JS app:

module.js:549 throw err; ^

Error: Cannot find module 'web3-requestManager' 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. (/home/robert/Documents/ethereum-demo-tools/VOTING-APP/chat-vote-results-nodejs-app/node_modules/web3/packages/web3-core/src/index.js:26:22) 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) Waiting for the debugger to disconnect...

This the command I used to do that. It took a fair amount of time to complete so for a while I thought the install had hung. It took almost 10 minutes to fully install:

npm install ethereum/web3.js#develop --save --verbose

After that I was able to run my Node.js app.

nickjuntilla commented 6 years ago

For deploying to firebase functions it seems they use yarn and removing the ^ allowed it to deploy successfully for me. Apparently yarn has trouble parsing this version syntax for nested dependencies.

maginkgo commented 6 years ago

@nickjuntilla thanks. It worked!

sasikumar13 commented 6 years ago

thanks vsdigitall my error cleared.. Error: Cannot find module 'web3-requestManager'

reinstalling helps:

npm r web3

npm i web3

marcelovue commented 6 years ago

I started getting this error after I ran npm update, I had to get the original package.json that was in my remote github, remove the local node_modules and then run: npm install

wjmelements commented 5 years ago

I have seen this after npm audit fix which downgraded my web3 to the deprecated 1.0.0-beta2. The fix was to return to the non-broken version.

HP213 commented 5 years ago

npm install web3@1.0.0-beta.26, just go for it