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

Serverless.com offline mode: Error: Cannot find module web3-requestManager #1234

Closed
ghost opened this issue Dec 15, 2017 · 3 comments
Closed

Comments

@ghost
Copy link

ghost commented Dec 15, 2017

  • Running web3.js 1.0.0-beta-18
  • Error occurs inside a javascript/node function in serverless running in local/offline mode

foo/list.js:

'use strict';

const AWS = require('aws-sdk');
const Web3 = require('web3');

module.exports.list = (event, context, callback) => {
    var web3 = new Web3();
    var provider = "https://ropsten.infura.io/xxx";
    web3.setProvider(new web3.providers.HttpProvider(provider));
    var account = "foo";
    var balanceWei = web3.eth.getBalance(account).toNumber();
    // create a response
    const response = {
      statusCode: 200,
      body: JSON.stringify([balanceWei]),
    };
    callback(null, response);
};
$ serverless offline start
Serverless: Starting Offline: dev/us-east-1.
...
Serverless: Offline listening on http://localhost:3000
Serverless: Error while loading list
[ 'Error: Cannot find module \'web3-requestManager\'',
  'at Function.Module._resolveFilename (module.js:542:15)',
  'at Function.Module._load (module.js:472:25)',
  'at Module.require (module.js:585:17)',
  'at require (internal/module.js:11:18)',
  'at Object.<anonymous> (/Path/To/Foo/node_modules/web3/packages/web3-core/src/index.js:26:22)',
  'at Module._compile (module.js:641:30)',
  'at Object.Module._extensions..js (module.js:652:10)',
  'at Module.load (module.js:560:32)',
  'at tryModuleLoad (module.js:503:12)',
  'at Function.Module._load (module.js:495:3)',
  'at Module.require (module.js:585:17)',
  'at require (internal/module.js:11:18)',
  'at Object.<anonymous> (/node_modules/web3/src/index.js:32:12)',
  'at Module._compile (module.js:641:30)',
  'at Object.Module._extensions..js (module.js:652:10)',
  'at Module.load (module.js:560:32)',
  'at tryModuleLoad (module.js:503:12)',
  'at Function.Module._load (module.js:495:3)',
  'at Module.require (module.js:585:17)',
  'at require (internal/module.js:11:18)',
  'at Object.<anonymous> (/Path/To/Foo/bulbs/list.js:4:14)',
  'at Module._compile (module.js:641:30)',
  'at Object.Module._extensions..js (module.js:652:10)',
  'at Module.load (module.js:560:32)',
  'at tryModuleLoad (module.js:503:12)',
  'at Function.Module._load (module.js:495:3)',
  'at Module.require (module.js:585:17)',
  'at require (internal/module.js:11:18)',
  'at Object.createHandler (/Path/To/Foo/node_modules/serverless-offline/src/functionHelper.js:35:21)',
  'at handler (/Path/To/Foo/node_modules/serverless-offline/src/index.js:499:40)',
  'at Object.internals.handler (/Path/To/Foo/node_modules/hapi/lib/handler.js:96:36)',
  'at request._protect.run (/Path/To/Foo/node_modules/hapi/lib/handler.js:30:23)',
  'at module.exports.internals.Protect.internals.Protect.run (/Path/To/Foo/node_modules/hapi/lib/protect.js:64:5)',
  'at exports.execute (/Path/To/Foo/node_modules/hapi/lib/handler.js:24:22)',
  'at each (/Path/To/Foo/node_modules/hapi/lib/request.js:384:16)',
  'at iterate (/Path/To/Foo/node_modules/items/lib/index.js:36:13)',
  'at done (/Path/To/Foo/node_modules/items/lib/index.js:28:25)',
  'at module.exports.internals.Auth.internals.Auth._authenticate (/Path/To/Foo/node_modules/hapi/lib/auth.js:210:16)',
  'at internals.Auth.authenticate (/Path/To/Foo/node_modules/hapi/lib/auth.js:202:17)',
  'at each (/Path/To/Foo/node_modules/hapi/lib/request.js:384:16)',
  'at iterate (/Path/To/Foo/node_modules/items/lib/index.js:36:13)',
  'at done (/Path/To/Foo/node_modules/items/lib/index.js:28:25)',
  'at internals.state (/Path/To/Foo/node_modules/hapi/lib/route.js:357:16)',
  'at each (/Path/To/Foo/node_modules/hapi/lib/request.js:384:16)',
  'at iterate (/Path/To/Foo/node_modules/items/lib/index.js:36:13)',
  'at Object.exports.serial (/Path/To/Foo/node_modules/items/lib/index.js:39:9)',
  'at internals.Request._lifecycle (/Path/To/Foo/node_modules/hapi/lib/request.js:387:11)',
  'at internals.Request._execute (/Path/To/Foo/node_modules/hapi/lib/request.js:302:21)',
  'at Domain.request._protect.enter (/Path/To/Foo/node_modules/hapi/lib/connection.js:261:25)',
  'at Domain.run (domain.js:227:14)',
  'at module.exports.internals.Protect.internals.Protect.enter (/Path/To/Foo/node_modules/hapi/lib/protect.js:80:17)',
  'at Server.<anonymous> (/Path/To/Foo/node_modules/hapi/lib/connection.js:259:30)',
  'at Server.emit (events.js:159:13)',
  'at parserOnIncoming (_http_server.js:619:12)' ]
@OR13
Copy link

OR13 commented Jan 19, 2018

This error is discussed here: #966

I have found that it can resurface randomly with lerna, yarn, npm version changes, etc...

Confirm that cat node_modules/web3/package.json

has something like:

  "types": "index.d.ts",
  "version": "1.0.0-beta.27"
}

at the bottom. the version should match your package.json, but you may find it does not when seeing this error.

Manually installing a specific version number seems to resolve this issue:

npm install web3@1.0.0-beta.27 --save

@wtam
Copy link

wtam commented Jan 25, 2018

@OR13, not sure what is the different, I still got the error with web3@1.0.0-beta.27. FYI I'm on Win10 and this error appear when run the docker-compose up which I got a nodejs app using web3

@nivida
Copy link
Contributor

nivida commented Aug 10, 2018

Please ask this question on https://ethereum.stackexchange.com/

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

3 participants