Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
guidosegni opened this issue Jul 31, 2017 · 53 comments
Closed

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

guidosegni opened this issue Jul 31, 2017 · 53 comments

Comments

@guidosegni
Copy link

guidosegni commented Jul 31, 2017

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
Copy link

Moejoe90 commented Aug 1, 2017

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

@jdkanani
Copy link
Contributor

jdkanani commented Aug 2, 2017

I am having same issue. @frozeman

@cowpig
Copy link

cowpig commented Aug 2, 2017

having the same issue

@frozeman
Copy link
Contributor

frozeman commented Aug 3, 2017

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

@frozeman frozeman closed this as completed Aug 3, 2017
frozeman added a commit that referenced this issue Aug 3, 2017
@jefflau
Copy link

jefflau commented Aug 4, 2017

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
Copy link

jefflau commented Aug 4, 2017

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
Copy link

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

@frozeman
Copy link
Contributor

frozeman commented Aug 9, 2017

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

@frozeman
Copy link
Contributor

frozeman commented Aug 9, 2017

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
Copy link

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
Copy link
Contributor

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

@jdkanani
Copy link
Contributor

@frozeman I am still getting this error.

@jdkanani
Copy link
Contributor

I think I found the problem. Checkout: yarnpkg/yarn#711

Yarn doesn't handle nested node_modules as npm does.

@pcjose
Copy link

pcjose commented Aug 16, 2017

I added this in the .bashrc

NODE_PATH=${HOME}/node_modules

and the problem was solved.

@robert-zaremba
Copy link

robert-zaremba commented Aug 18, 2017

@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: yarnpkg/yarn#711 (comment)

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

@tcoulter
Copy link

tcoulter commented Aug 18, 2017

@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
Copy link

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
Copy link
Contributor

jdkanani commented Aug 24, 2017

@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
Copy link
Contributor

By the way, for webpack to work, this request #1006 needs to get merged too.

@stefanhuber
Copy link

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

@jdkanani
Copy link
Contributor

jdkanani commented Aug 24, 2017

@stefanhuber Try adding extra module directories in webpack resolve as I mentioned above #966 (comment) and see if works?

@stefanhuber
Copy link

@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
Copy link
Contributor

jdkanani commented Aug 24, 2017

@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
Copy link

@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
Copy link
Contributor

cmditch commented Aug 24, 2017

@varadarajana
Copy link

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

@lsaether
Copy link

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
Copy link

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

@srameshr
Copy link

srameshr commented Jan 22, 2018

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
Copy link

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

Thanks!

@elijahmurray
Copy link

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

@vsdigitall
Copy link

vsdigitall commented Feb 16, 2018

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
Copy link

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
Copy link

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
Copy link

roppa commented Mar 14, 2018

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

@arashkiani
Copy link

arashkiani commented Mar 23, 2018

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

@ondratra
Copy link

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
Copy link

roschler commented Apr 1, 2018

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
Copy link

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
Copy link

@nickjuntilla thanks. It worked!

@sasikumar13
Copy link

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

reinstalling helps:

npm r web3

npm i web3

@marcelovue
Copy link

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
Copy link

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
Copy link

HP213 commented Oct 20, 2018

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

@dconroy
Copy link

dconroy commented Dec 19, 2018

how do we get "npm audit fix" not default to deprecated versions of web3?

@Kishanjvaghela
Copy link

Kishanjvaghela commented Jan 3, 2019

@cosminstefanxp I had same problem with web and firebase.. this is worked for me

  • remove the ^ for web3. (In package.json). Mine is like this "web3": "1.0.0-beta.37"
  • delete node_modules
  • delete package-lock.json
  • then npm install

@tvance929
Copy link

@Kishanjvaghela - that was it for me! My package had a github address for web3... i replaced it with your version then followed your steps and Im up. Thanks so much!

bohendo pushed a commit to connext/indra that referenced this issue Apr 16, 2019
nachomazzara pushed a commit to nachomazzara/web3.js that referenced this issue Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests