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

How to use/bundle the web3 package correctly? #224

Closed
rhlsthrm opened this issue Sep 14, 2017 · 52 comments
Closed

How to use/bundle the web3 package correctly? #224

rhlsthrm opened this issue Sep 14, 2017 · 52 comments

Comments

@rhlsthrm
Copy link

rhlsthrm commented Sep 14, 2017

This is a Bug Report

Description

For bug reports:

  • What went wrong?
    Stuck on packaging after running serverless webpack for a very long time > 10 minutes.
  • What did you expect should have happened?
    Packaged sooner than that.
  • What was the config you used?
// webpack.config.js

var path = require('path')
const slsw = require('serverless-webpack')
var nodeExternals = require('webpack-node-externals')

var entries = slsw.lib.entries

const models = [
  './models/charge.model.js',
  './models/metrics.model.js',
  './models/user.model.js'
]
for (let i in models) {
  entries[models[i]] = models[i]
}

module.exports = {
  entry: entries,
  target: 'node',
  // Generate sourcemaps for proper error messages
  devtool: 'eval',
  // Since 'aws-sdk' is not compatible with webpack,
  // we exclude all node dependencies
  externals: [nodeExternals()],
  // Run babel on all .js files and skip those in node_modules
  module: {
    loaders: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
        include: __dirname,
        exclude: /node_modules/
      }
    ]
  },
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js'
  }
}
  • What stacktrace or error message from your provider did you see?
    This is the message it is stuck on:
    Serverless: Packing external modules: babel-runtime@^6.25.0, sequelize@^4.8.3, nodemailer@^4.0.1, hat@0.0.3, promise@^8.0.1, web3@^1.0.0-beta.18, truffle-contract@^3.0.0, basic-auth@^2.0.0

  • Serverless-Webpack Version you're using: 3.0.0

  • Webpack version you're using: 3.5.6

  • Serverless Framework Version you're using: 1.22.0

  • Operating System: macOS 10.12.6

@HyperBrain
Copy link
Member

HyperBrain commented Sep 14, 2017

Hi @rhlsthrm ,

this sound like your project setup triggered the Serverless native packaging for some reason, which should not be.

With version 3.0.0 you should enable entry point auto detection with entry: slsw.entries and set your handlers correctly in your serverless.yml instead of building them manually. This is needed especially if you use individual packaging.

In your serverless.yml just check that the handlers for the functions are set as follows:

chargefunc:
  ...
  handler: models/charge.model.js
metricsfunc:
  ...
  handler: models/metrics.model.js

Notice the missing ./ here!

BTW: Since Webpack 2.x the loaders should be configured in module: rules instead of module: loaders (see the webpack 2.x/3.x online documentation)

@HyperBrain
Copy link
Member

FYI: To analyze such behavior you can add --verbose to the serverless command line. The webpack plugin will print more details then which allow to see exactly where it is stuck.

@rhlsthrm
Copy link
Author

@HyperBrain thanks for the response. How can I tell if the setup triggers the Serverless native packaging? I want to make sure it's optimizing the packaging with webpack properly.

Also I am using slsw.lib.entries as my entry point auto detection, I think you made a typo when you mentioned slsw.entries, so that should be working. I was manually adding the models files which are required dependencies in my project. I think the auto detection is adding them manually though, so not sure I need to do this.

My handlers are configured as you mentioned. Thanks for the tip on configuring webpack for version 3. Here is my new config export:

module.exports = {
  entry: entries,
  target: 'node',
  // Generate sourcemaps for proper error messages
  devtool: 'eval',
  // Since 'aws-sdk' is not compatible with webpack,
  // we exclude all node dependencies
  externals: [nodeExternals()],
  // Run babel on all .js files and skip those in node_modules
  module: {
    rules: [
      {
        test: /\.js$/,
        use: [
          {
            loader: 'babel-loader'
          }
        ],
        include: __dirname,
        exclude: /node_modules/
      }
    ]
  },
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js'
  }
}

@HyperBrain
Copy link
Member

@rhlsthrm Apologies for the typo, yes it is slsw.lib.entries. You should not need to do anything manually with the entries as slsw analyzes your functions and properly sets them.
To get further with the issue. Can you try to do a serverless package --verbose? This only runs the packaging step and does not do the actual deployment. Afterwards you find the zip packages for the functions that would be uploaded in the .serverless folder.
Please check from the verbose output, where exactly the time is spent and also, if the content in the zip files is the expected one (especially the contents of the node_modules).
Another thing that is important is, that you have the aws-sdk in your devDependencies, so that it is not packaged.
It would be helpful if you can post the important parts of the verbose output here (I added timing outputs in verbose mode for the packaging steps).

@rhlsthrm
Copy link
Author

rhlsthrm commented Sep 14, 2017

Thanks again for the help!

Packaging has been running for quite a while and this is some of the output:

See updated trace below.

I see that some of these functions are taking a long time to zip (293524 ms, 308840 ms). How can I go about finding out what is taking these particular functions so long to pack (there is not a lot of code so it must be the dependencies)? Any ideas on what I can do to make it better? One thing I am noticing is all of these that are taking a long time are using web3 so I wonder if that particular dependency is causing issues.

Edit:

The packaging step finished with an error. This is the full trace:

Serverless: Fetch dependency graph from /Users/Rahul/Desktop/connext/ConnextAPI/src/server/package.json
Serverless: Packing external modules: babel-runtime@^6.25.0, basic-auth@^2.0.0, sequelize@^4.8.3, hat@0.0.3, promise@^8.0.1, nodemailer@^4.0.1, web3@^1.0.0-beta.18, truffle-contract@^3.0.0
Serverless: Package took [69413 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/authorizer [5147 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/authorizer [4338 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/hello [3824 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/hello [5609 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/key [4145 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/key [4521 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/register [4114 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/register [5706 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/forgotPassword [4349 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/forgotPassword [4469 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/resetTokenValid [4585 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/resetTokenValid [4368 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/resetPassword [4698 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/resetPassword [3924 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/tokenize [4716 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/tokenize [4414 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/charge [4831 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/charge [2964 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getChargeHistory [3931 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getChargeHistory [4179 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getOwner [3967 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getOwner [2544 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getChargebackDestination [4752 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getChargebackDestination [2722 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getTokenContractAddress [4916 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getTokenContractAddress [2517 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getBalance [3616 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getBalance [2951 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getActorAllowed [3882 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getActorAllowed [2799 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/postAuthorizeActor [4066 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/postAuthorizeActor [2682 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsChargebackableJson [4526 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsChargebackableJson [4449 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsErc20Json [3967 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsErc20Json [4388 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsErc20BasicJson [4735 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsErc20BasicJson [4527 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsOwnedJson [3918 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsOwnedJson [4621 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsVaultJson [3994 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsVaultJson [4496 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/authorizer [2511 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/hello [963 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/key [2048 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/register [2169 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/forgotPassword [2043 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/resetTokenValid [2296 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/resetPassword [2203 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/tokenize [1182 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/charge [293524 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getChargeHistory [3565 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getOwner [308840 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getChargebackDestination [253417 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getTokenContractAddress [276670 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getBalance [257337 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getActorAllowed [265376 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/postAuthorizeActor [237548 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsChargebackableJson [52 ms]

  Type Error ---------------------------------------------

  Cannot set property 'package' of undefined

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless

  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           8.2.1
     Serverless Version:     1.22.0

I am not sure how to debug that final error. Any ideas on where to look?

@HyperBrain
Copy link
Member

Ok. What is very interesting are the charge [293524 ms] and getOwner [308840 ms].

All other packaging parts are ok - if you do individual packaging it is expected that it needs more time as every function is optimized separately including its referenced modules. So the copy/prune/zip with about 10-15 seconds per function is ok.

BUT: There is definitely something wrong with the ZIP function at charge and getOwner. The copy/prune for these two is fully ok. As copy/prune is fast, it cannot be the dependencies, otherwise this would have taken the same long time as the zipping.

Can you check, if there is something special with the 2 zips that are finally in .serverless?

@rhlsthrm
Copy link
Author

rhlsthrm commented Sep 14, 2017

Nothing weird with the zip itself, but the node_modules folder is >300MB:
charge

Looking into it, I see that the web3 library is indeed >300MB itself! This must be what is causing the issue. I guess I need to see if I can somehow reduce the size of the library, or only import what I need?

Edit:

I looked at the web3 package that I have installed with npm install web3 and I see that it is only 1.6MB on my disk. That means there is something weird happening when it is getting packaged by Webpack. Do I have to do something special to include it as is?

@HyperBrain
Copy link
Member

Yes. That's indeed a problem. You could do one experiment: try to bundle the web3 library with webpack, so that it only fetches code and dependencies used. That might reduce the size dramatically. You can do that with:

externals: [nodeExternals( { whitelist: [ 'web3' ] } )]

This will let Webpack bundle the module and the webpack plugin will only package the remaining 2nd level dependencies that are used by the code of web3 that is actually required. Just give it a try - although I cannot give any guarantee that it will work as expected ;-)

@rhlsthrm
Copy link
Author

That didn't seem to work, I'm getting warnings and errors:

WARNING in ./node_modules/web3/packages/web3-bzz/node_modules/any-promise/register.js
24:14-37 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/BufferUtil.js
Module not found: Error: Can't resolve '../build/Release/bufferutil' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib'
 @ ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/BufferUtil.js 9:19-57
 @ ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/WebSocketFrame.js
 @ ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/websocket.js
 @ ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/index.js
 @ ./node_modules/web3/packages/web3-providers-ws/src/index.js
 @ ./node_modules/web3/packages/web3-core-requestmanager/src/index.js
 @ ./node_modules/web3/packages/web3-core/src/index.js
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./lib/deployVault.js
 @ ./functions/charge/charge.js

WARNING in ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/Validation.js
Module not found: Error: Can't resolve '../build/Release/validation' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib'
 @ ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/Validation.js 9:21-59
 @ ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/WebSocketConnection.js
 @ ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/websocket.js
 @ ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/index.js
 @ ./node_modules/web3/packages/web3-providers-ws/src/index.js
 @ ./node_modules/web3/packages/web3-core-requestmanager/src/index.js
 @ ./node_modules/web3/packages/web3-core/src/index.js
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./lib/deployVault.js
 @ ./functions/charge/charge.js

WARNING in ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/BufferUtil.js
Module not found: Error: Can't resolve '../build/default/bufferutil' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib'
 @ ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/BufferUtil.js 11:19-57
 @ ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/WebSocketFrame.js
 @ ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/websocket.js
 @ ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/index.js
 @ ./node_modules/web3/packages/web3-providers-ws/src/index.js
 @ ./node_modules/web3/packages/web3-core-requestmanager/src/index.js
 @ ./node_modules/web3/packages/web3-core/src/index.js
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./lib/deployVault.js
 @ ./functions/charge/charge.js

WARNING in ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/Validation.js
Module not found: Error: Can't resolve '../build/default/validation' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib'
 @ ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/Validation.js 11:21-59
 @ ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/WebSocketConnection.js
 @ ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/lib/websocket.js
 @ ./node_modules/web3/packages/web3-providers-ws/node_modules/websocket/index.js
 @ ./node_modules/web3/packages/web3-providers-ws/src/index.js
 @ ./node_modules/web3/packages/web3-core-requestmanager/src/index.js
 @ ./node_modules/web3/packages/web3-core/src/index.js
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./lib/deployVault.js
 @ ./functions/charge/charge.js

ERROR in ./node_modules/web3/packages/web3-eth-accounts/node_modules/scrypt/index.js
Module not found: Error: Can't resolve './build/Release/scrypt' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth-accounts/node_modules/scrypt'
 @ ./node_modules/web3/packages/web3-eth-accounts/node_modules/scrypt/index.js 3:19-52
 @ ./node_modules/web3/packages/web3-eth-accounts/node_modules/scrypt.js/node.js
 @ ./node_modules/web3/packages/web3-eth-accounts/src/index.js
 @ ./node_modules/web3/packages/web3-eth/src/index.js
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./lib/deployVault.js
 @ ./functions/charge/charge.js

  Error --------------------------------------------------

  Webpack compilation error, see above

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless

  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           8.2.1
     Serverless Version:     1.22.0

If you look at my edit, you can see that the installed package on the disk is much, much smaller. Something is happening when the package is getting processed by webpack. Any idea what I can do?

Thanks again for all the help.

@HyperBrain
Copy link
Member

Right now I have not really an idea what can be done as I never used the web3 package nor packaged it with any service. I'd have to do some tests with it first.
I will change the subject of this issue and add the help-wanted tag. Maybe someone who already solved the problem will see it and can help out here.

@HyperBrain HyperBrain changed the title Stuck on "Packing external modules" How to use/bundle the web3 package correctly? Sep 14, 2017
@rhlsthrm
Copy link
Author

Thanks for reaching out. Is this problem unique to web3? I'm thinking it could be more generic where some packages bundle into something much bigger than what is desired, and there is some workaround for that. You have never seen an issue where the bundled size is something crazy like this?

@HyperBrain
Copy link
Member

Honestly - No 😃 . The biggest module that we used was the unicode7 module, but we bundled that on purpose as the code needed it. And in general, our lambda zips at work are all between 5 and 20 MB.

The question is, if web3 is intended to run within a Lambda (as opposed to a server environment) as is or if you might just include/bundle the built js (from the dist directory) which is much smaller (in case it works properly in the node environment).

Maybe you should also ask the question on https://gitter.im/ethereum/web3.js

@rhlsthrm
Copy link
Author

The question is, if web3 is intended to run within a Lambda (as opposed to a server environment)

I'm not sure what you mean by this. There shouldn't be any distinction to the library whether or not it is running on lambda versus a server right?

I'm just finding it strange that the size on disk is normal, and only balloons to that insane size after i run the webpack command on it.

@HyperBrain
Copy link
Member

I did some tries with web3 and experienced some strange installation issues (errors while npm install). It seems that the whole package uses lerna which combines the used modules somehow by linking them.
Maybe that's the reason for the wrong packaging.
Internally the webpack plugin does a npm install and then bundles the node modules directory (after doing an npm prune for each function to remove the unused functions.
I'll do some further experiments and try to get web3 installed correctly on my machine.

@HyperBrain
Copy link
Member

HyperBrain commented Sep 18, 2017

@rhlsthrm I did some further experiments with web3 and found out that it uses lerna to set up the modules during npm install. Maybe that is related to #201 and @emrosenf can help out here.
@emrosenf Did you check with version 3.0.0 and lerna again?

@rhlsthrm
Copy link
Author

@HyperBrain thank you so much for the help. It appears I'm on the cutting edge here and hopefully all these pains will solve other's problems in the future. I'll wait to see if @emrosenf can help.

@rhlsthrm
Copy link
Author

@HyperBrain unfortunately the dist/ versions of the library don't work in a node environment and this issue is blocking me now. How can I help to debug this further? If you keep helping me that would be much appreciated! I'll comment on the other issue to see if I can get some help there. Is the code you pushed to fix that issue in the release now?

@emrosenf
Copy link

emrosenf commented Sep 18, 2017 via email

@HyperBrain
Copy link
Member

HyperBrain commented Sep 18, 2017

@rhlsthrm I just found this: https://github.com/uzyn/web3-loader. This loader might be able to remove the web3 dependency from the bundled code and according to the documentation

You can also interact with the ininitialized web3 instance without having to import and initialize web3 in your code.

If that works you should end up with minimal dependencies as you only import the contract and web3 through it. As soon as web3 isn't a dependency of the compiled code anymore, it could work. In general the compilation that is triggered together with npm install and web3 might be a problem without the loader.

If that does not help, you could add some logging to either packageExternalModules.js in the plugin (that's where the node module dependencies are installed) or packModules.js (the zipping of the output).

Additionally you could prepare a minimal project with which I would be able to reproduce the issue.

@rhlsthrm
Copy link
Author

@HyperBrain this is interesting, but I'm not sure it will work for me. This doesn't look like it will deploy contracts on demand programmatically, but rather it's designed to deploy contracts with a new build or else use previously deployed contracts.

I'd love to keep trying to get this to work, since enabling web3 functionality inside a lambda function would be great for the whole Ethereum development community as well!

@HyperBrain
Copy link
Member

After some deeper thoughts about the topic it seems to me that the bytecode compilation should be done locally BEFORE serverless triggers the webpack compile. In fact the web3 package is not really needed within the deloy phase in that case. The Serverless deploy step should just upload the contract as well as the JS code in one transaction.

Such a scenario would be best implemented as new Serverless plugin, that takes care of the compile and hooks into the deploy event to deploy the contracts. However a "non-deploying" derivate of the webpack plugins (web3 and sol loaders) would be needed, so that the new Serverless plugin can take care of the contract deployment.

@rhlsthrm
Copy link
Author

@HyperBrain not sure I understand exactly what you are saying here.

Web3 is needed as a dependency in order to interact with the Ethereum blockchain. In my app, I need web3 to deploy my Solidity contracts, as well as interact with contracts that are already on the blockchain. It is an in-app dependency that I need when my endpoint code runs.

I wonder is there a way to package it with all the dependencies into a sort of "binary" package that can be uploaded to lambda as is?

@rhlsthrm
Copy link
Author

@HyperBrain major update to share. I updated all my packages in my system and things are behaving VERY different now, seemingly in a good way. When I run serverless package --verbose, things appear to package normally now. However I still get an error at the end of the packaging step. Here is the full output:

$ serverless package --verbose                                                                                   10:53:26
Serverless: Using multi-compile (individual packaging)
Serverless: Bundling with Webpack...
Time: 2643ms
                               Asset     Size  Chunks             Chunk Names
functions/middleware/authenticate.js  8.77 kB       0  [emitted]  functions/middleware/authenticate
   [0] ./functions/middleware/authenticate.js 3.04 kB {0} [built]
   [1] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [2] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [3] external "basic-auth" 42 bytes {0} [not cacheable]
   [4] ./lib/sequelize.js 1.42 kB {0} [built]
   [5] external "sequelize" 42 bytes {0} [not cacheable]
Time: 2625ms
                     Asset     Size  Chunks             Chunk Names
functions/hello/handler.js  6.07 kB       0  [emitted]  functions/hello/handler
   [0] ./functions/hello/handler.js 1.2 kB {0} [built]
   [1] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [2] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [3] ./lib/response-lib.js 866 bytes {0} [built]
   [4] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
Time: 2624ms
                 Asset     Size  Chunks             Chunk Names
functions/users/key.js  10.2 kB       0  [emitted]  functions/users/key
   [0] ./functions/users/key.js 2.4 kB {0} [built]
   [1] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [2] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [3] ./lib/sequelize.js 1.42 kB {0} [built]
   [4] external "sequelize" 42 bytes {0} [not cacheable]
   [5] ./lib/hashPassword.js 401 bytes {0} [built]
   [6] external "crypto" 42 bytes {0} [not cacheable]
   [7] ./lib/response-lib.js 866 bytes {0} [built]
   [8] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
Time: 2899ms
                      Asset     Size  Chunks             Chunk Names
functions/users/register.js  15.4 kB       0  [emitted]  functions/users/register
   [0] external "crypto" 42 bytes {0} [not cacheable]
   [1] ./functions/users/register.js 3.84 kB {0} [built]
   [2] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [3] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [4] ./lib/sequelize.js 1.42 kB {0} [built]
   [5] external "sequelize" 42 bytes {0} [not cacheable]
   [6] external "hat" 42 bytes {0} [not cacheable]
   [7] ./lib/hashPassword.js 401 bytes {0} [built]
   [8] ./lib/sendEmail.js 1.81 kB {0} [built]
   [9] external "promise" 42 bytes {0} [not cacheable]
  [10] ./lib/mailer.js 517 bytes {0} [built]
  [11] external "nodemailer" 42 bytes {0} [not cacheable]
  [12] ./lib/response-lib.js 866 bytes {0} [built]
  [13] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
Time: 2623ms
                            Asset     Size  Chunks             Chunk Names
functions/users/forgotPassword.js  11.4 kB       0  [emitted]  functions/users/forgotPassword
   [0] ./functions/users/forgotPassword.js 3.21 kB {0} [built]
   [1] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [2] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [3] ./lib/sequelize.js 1.42 kB {0} [built]
   [4] external "sequelize" 42 bytes {0} [not cacheable]
   [5] external "crypto" 42 bytes {0} [not cacheable]
   [6] ./lib/mailer.js 517 bytes {0} [built]
   [7] external "nodemailer" 42 bytes {0} [not cacheable]
   [8] ./lib/response-lib.js 866 bytes {0} [built]
   [9] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
Time: 2622ms
                             Asset     Size  Chunks             Chunk Names
functions/users/resetTokenValid.js  8.67 kB       0  [emitted]  functions/users/resetTokenValid
   [0] ./functions/users/resetTokenValid.js 1.79 kB {0} [built]
   [1] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [2] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [3] ./lib/sequelize.js 1.42 kB {0} [built]
   [4] external "sequelize" 42 bytes {0} [not cacheable]
   [5] ./lib/response-lib.js 866 bytes {0} [built]
   [6] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
Time: 2622ms
                           Asset     Size  Chunks             Chunk Names
functions/users/resetPassword.js  10.5 kB       0  [emitted]  functions/users/resetPassword
   [0] external "crypto" 42 bytes {0} [not cacheable]
   [1] ./functions/users/resetPassword.js 2.69 kB {0} [built]
   [2] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [3] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [4] ./lib/sequelize.js 1.42 kB {0} [built]
   [5] external "sequelize" 42 bytes {0} [not cacheable]
   [6] ./lib/hashPassword.js 401 bytes {0} [built]
   [7] ./lib/response-lib.js 866 bytes {0} [built]
   [8] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
Time: 2622ms
                       Asset     Size  Chunks             Chunk Names
functions/charge/tokenize.js  6.15 kB       0  [emitted]  functions/charge/tokenize
   [0] ./functions/charge/tokenize.js 1.28 kB {0} [built]
   [1] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [2] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [3] ./lib/response-lib.js 866 bytes {0} [built]
   [4] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
Time: 2927ms
                     Asset     Size  Chunks             Chunk Names
functions/charge/charge.js  29.7 kB       0  [emitted]  functions/charge/charge
   [0] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [1] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [2] ./functions/charge/charge.js 4.81 kB {0} [built]
   [3] ./lib/deployVault.js 1.7 kB {0} [built]
   [4] ./lib/Vault.js 885 bytes {0} [built]
   [5] ./lib/web3.js 1.1 kB {0} [built]
   [6] external "web3" 42 bytes {0} [not cacheable]
   [7] external "truffle-contract" 42 bytes {0} [not cacheable]
   [8] ./build/contracts/Vault.json 11.9 kB {0} [built]
   [9] ./lib/sequelize.js 1.42 kB {0} [built]
  [10] external "sequelize" 42 bytes {0} [not cacheable]
  [11] ./lib/response-lib.js 866 bytes {0} [built]
  [12] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
Time: 2621ms
                               Asset     Size  Chunks             Chunk Names
functions/charge/getChargeHistory.js  9.38 kB       0  [emitted]  functions/charge/getChargeHistory
   [0] ./functions/charge/getChargeHistory.js 2.49 kB {0} [built]
   [1] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [2] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [3] ./lib/sequelize.js 1.42 kB {0} [built]
   [4] external "sequelize" 42 bytes {0} [not cacheable]
   [5] ./lib/response-lib.js 866 bytes {0} [built]
   [6] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
Time: 2896ms
                      Asset     Size  Chunks             Chunk Names
functions/vault/getOwner.js  22.3 kB       0  [emitted]  functions/vault/getOwner
   [0] ./functions/vault/getOwner.js 1.54 kB {0} [built]
   [1] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [2] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [3] ./lib/Vault.js 885 bytes {0} [built]
   [4] ./lib/web3.js 1.1 kB {0} [built]
   [5] external "web3" 42 bytes {0} [not cacheable]
   [6] external "truffle-contract" 42 bytes {0} [not cacheable]
   [7] ./build/contracts/Vault.json 11.9 kB {0} [built]
   [8] ./lib/response-lib.js 866 bytes {0} [built]
   [9] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
Time: 2896ms
                                      Asset     Size  Chunks             Chunk Names
functions/vault/getChargebackDestination.js  22.5 kB       0  [emitted]  functions/vault/getChargebackDestination
   [0] ./functions/vault/getChargebackDestination.js 1.62 kB {0} [built]
   [1] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [2] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [3] ./lib/Vault.js 885 bytes {0} [built]
   [4] ./lib/web3.js 1.1 kB {0} [built]
   [5] external "web3" 42 bytes {0} [not cacheable]
   [6] external "truffle-contract" 42 bytes {0} [not cacheable]
   [7] ./build/contracts/Vault.json 11.9 kB {0} [built]
   [8] ./lib/response-lib.js 866 bytes {0} [built]
   [9] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
Time: 2896ms
                                     Asset     Size  Chunks             Chunk Names
functions/vault/getTokenContractAddress.js  22.4 kB       0  [emitted]  functions/vault/getTokenContractAddress
   [0] ./functions/vault/getTokenContractAddress.js 1.6 kB {0} [built]
   [1] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [2] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [3] ./lib/Vault.js 885 bytes {0} [built]
   [4] ./lib/web3.js 1.1 kB {0} [built]
   [5] external "web3" 42 bytes {0} [not cacheable]
   [6] external "truffle-contract" 42 bytes {0} [not cacheable]
   [7] ./build/contracts/Vault.json 11.9 kB {0} [built]
   [8] ./lib/response-lib.js 866 bytes {0} [built]
   [9] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
Time: 2896ms
                        Asset     Size  Chunks             Chunk Names
functions/vault/getBalance.js  22.4 kB       0  [emitted]  functions/vault/getBalance
   [0] ./functions/vault/getBalance.js 1.55 kB {0} [built]
   [1] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [2] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [3] ./lib/Vault.js 885 bytes {0} [built]
   [4] ./lib/web3.js 1.1 kB {0} [built]
   [5] external "web3" 42 bytes {0} [not cacheable]
   [6] external "truffle-contract" 42 bytes {0} [not cacheable]
   [7] ./build/contracts/Vault.json 11.9 kB {0} [built]
   [8] ./lib/response-lib.js 866 bytes {0} [built]
   [9] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
Time: 2895ms
                             Asset     Size  Chunks             Chunk Names
functions/vault/getActorAllowed.js  22.5 kB       0  [emitted]  functions/vault/getActorAllowed
   [0] ./functions/vault/getActorAllowed.js 1.7 kB {0} [built]
   [1] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [2] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [3] ./lib/Vault.js 885 bytes {0} [built]
   [4] ./lib/web3.js 1.1 kB {0} [built]
   [5] external "web3" 42 bytes {0} [not cacheable]
   [6] external "truffle-contract" 42 bytes {0} [not cacheable]
   [7] ./build/contracts/Vault.json 11.9 kB {0} [built]
   [8] ./lib/response-lib.js 866 bytes {0} [built]
   [9] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
Time: 2895ms
                                Asset     Size  Chunks             Chunk Names
functions/vault/postAuthorizeActor.js  23.4 kB       0  [emitted]  functions/vault/postAuthorizeActor
   [0] ./functions/vault/postAuthorizeActor.js 2.52 kB {0} [built]
   [1] external "babel-runtime/regenerator" 42 bytes {0} [not cacheable]
   [2] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {0} [not cacheable]
   [3] ./lib/Vault.js 885 bytes {0} [built]
   [4] ./lib/web3.js 1.1 kB {0} [built]
   [5] external "web3" 42 bytes {0} [not cacheable]
   [6] external "truffle-contract" 42 bytes {0} [not cacheable]
   [7] ./build/contracts/Vault.json 11.9 kB {0} [built]
   [8] ./lib/response-lib.js 866 bytes {0} [built]
   [9] external "babel-runtime/core-js/json/stringify" 42 bytes {0} [not cacheable]
Time: 254ms
                                   Asset     Size  Chunks             Chunk Names
./build/contracts/Chargebackable.json.js  7.32 kB       0  [emitted]  ./build/contracts/Chargebackable.json
   [0] ./build/contracts/Chargebackable.json 4.3 kB {0} [built]
Time: 256ms
                          Asset     Size  Chunks             Chunk Names
./build/contracts/ERC20.json.js  4.67 kB       0  [emitted]  ./build/contracts/ERC20.json
   [0] ./build/contracts/ERC20.json 1.63 kB {0} [built]
Time: 256ms
                               Asset    Size  Chunks             Chunk Names
./build/contracts/ERC20Basic.json.js  3.7 kB       0  [emitted]  ./build/contracts/ERC20Basic.json
   [0] ./build/contracts/ERC20Basic.json 818 bytes {0} [built]
Time: 255ms
                          Asset     Size  Chunks             Chunk Names
./build/contracts/Owned.json.js  4.35 kB       0  [emitted]  ./build/contracts/Owned.json
   [0] ./build/contracts/Owned.json 1.53 kB {0} [built]
Time: 256ms
                          Asset     Size  Chunks             Chunk Names
./build/contracts/Vault.json.js  15.3 kB       0  [emitted]  ./build/contracts/Vault.json
   [0] ./build/contracts/Vault.json 11.9 kB {0} [built]
Serverless: Fetch dependency graph from /Users/Rahul/Desktop/connext/ConnextAPI/src/server/package.json
Serverless: Packing external modules: babel-runtime@^6.25.0, basic-auth@^2.0.0, hat@0.0.3, promise@^8.0.1, nodemailer@^4.0.1, web3@^1.0.0-beta2, truffle-contract@^3.0.0
Serverless: Package took [5804 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/authorizer [1358 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/authorizer [1451 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/hello [1307 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/hello [1464 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/key [1345 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/key [1603 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/register [1496 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/register [1888 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/forgotPassword [1074 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/forgotPassword [1629 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/resetTokenValid [953 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/resetTokenValid [1928 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/resetPassword [2060 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/resetPassword [2076 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/tokenize [1375 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/tokenize [2071 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/charge [1333 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/charge [1452 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getChargeHistory [746 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getChargeHistory [1573 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getOwner [1390 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getOwner [1646 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getChargebackDestination [1333 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getChargebackDestination [1935 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getTokenContractAddress [1376 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getTokenContractAddress [1576 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getBalance [940 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getBalance [1567 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getActorAllowed [1307 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getActorAllowed [1469 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/postAuthorizeActor [1426 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/postAuthorizeActor [1736 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsChargebackableJson [1424 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsChargebackableJson [1898 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsErc20Json [1171 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsErc20Json [1672 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsErc20BasicJson [837 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsErc20BasicJson [1942 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsOwnedJson [1374 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsOwnedJson [1948 ms]
Serverless: Copy modules: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsVaultJson [1024 ms]
Serverless: Prune: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsVaultJson [1919 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/authorizer [2083 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/hello [1197 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/key [1398 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/register [1118 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/forgotPassword [1109 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/resetTokenValid [1242 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/resetPassword [1095 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/tokenize [1071 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/charge [1813 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getChargeHistory [1269 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getOwner [1884 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getChargebackDestination [1967 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getTokenContractAddress [1834 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getBalance [1929 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/getActorAllowed [1892 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/postAuthorizeActor [2001 ms]
Serverless: Zip function: /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/buildContractsChargebackableJson [4 ms]

  Type Error ---------------------------------------------

  Cannot set property 'package' of undefined

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless

  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           8.2.1
     Serverless Version:     1.22.0

Can you help me to figure out what's going on with that error?

@HyperBrain
Copy link
Member

That sounds good 😄 . Can you do the package command again with SLS_DEBUG=* set and post the stacktrace that is shown at the very end right after the Type Error? Then I can see exactly what's going wrong in the end.

@rhlsthrm
Copy link
Author

Sorry, should have done that first, the message explicitly says to 😛.

Type Error ---------------------------------------------

  Cannot set property 'package' of undefined

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Stack Trace --------------------------------------------

TypeError: Cannot set property 'package' of undefined
    at ServerlessWebpack.setArtifactPath (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/serverless-webpack/lib/packageModules.js:20:18)
    at zip.call.tap.then.artifactPath (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/serverless-webpack/lib/packageModules.js:92:27)
From previous event:
    at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:358:22)
    at PluginManager.run (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:389:17)
    at variables.populateService.then (/usr/local/lib/node_modules/serverless/lib/Serverless.js:99:33)
    at runCallback (timers.js:781:20)
    at tryOnImmediate (timers.js:743:5)
    at processImmediate [as _immediateCallback] (timers.js:714:5)
From previous event:
    at Serverless.run (/usr/local/lib/node_modules/serverless/lib/Serverless.js:86:74)
    at serverless.init.then (/usr/local/lib/node_modules/serverless/bin/serverless:39:50)
    at <anonymous>

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless

  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           8.2.1
     Serverless Version:     1.22.0

@HyperBrain
Copy link
Member

That seems to be a bug with the function detection in the plugin. There seems to be a mismatch between the fetched functions and the actual entries. I think I can fix that, but I'll need a copy of the functions section from your serverless.yml. Additionally, do you now use only entry: slsw.lib.entries or do you expand the entry map in your webpack config programatically.
This information should be enough, so that I can provide a fix tomorrow.

@rhlsthrm
Copy link
Author

I expand the entry map programmatically. This is what my webpack config looks like:

var path = require('path')
const slsw = require('serverless-webpack')
var nodeExternals = require('webpack-node-externals')

var entries = slsw.lib.entries

const models = [
  './models/charge.model.js',
  './models/metrics.model.js',
  './models/user.model.js'
]
for (let i in models) {
  entries[models[i]] = models[i]
}

const contracts = [
  './build/contracts/Chargebackable.json',
  './build/contracts/ERC20.json',
  './build/contracts/ERC20Basic.json',
  './build/contracts/Owned.json',
  './build/contracts/Vault.json'
]

for (let i in contracts) {
  entries[contracts[i]] = contracts[i]
}

module.exports = {
  entry: entries,
  target: 'node',
  // Generate sourcemaps for proper error messages
  devtool: 'eval',
  // Since 'aws-sdk' is not compatible with webpack,
  // we exclude all node dependencies
  externals: [nodeExternals()],
  // Run babel on all .js files and skip those in node_modules
  module: {
    rules: [
      {
        test: /\.js$/,
        use: [
          {
            loader: 'babel-loader'
          }
        ],
        include: __dirname,
        exclude: /node_modules/
      }
    ]
  },
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js'
  }
}

There appears to be other problems that could be caused by things not getting imported correctly but I will deal with those later.

@HyperBrain
Copy link
Member

HyperBrain commented Sep 19, 2017

I think the models are already part of the slsw.lib.entries because they are defined as functions, so you should not add them manually. In general function entries must not be set because that will destroy the reverse lookup into Serverless for individual packaging.
The others (the contracts) are ok, but that triggers the bug in the plugin. But I know now, what the problem is, so I'm able to fix that.

@HyperBrain
Copy link
Member

HyperBrain commented Sep 19, 2017

BTW: The contract json files are needed as is in the app, i.e. you require them from the code? Then it would be better to bundle them with either the copy file webpack plugin or the file-loader.

Then you could use the "raw" slsw.lib.entries without any modification and let webpack bundle the json files.

@rhlsthrm
Copy link
Author

Yes, the contract json files are needed as is. OK I will look into that, I haven't used webpack much so I'll have to research a little but sounds straightforward.

@HyperBrain
Copy link
Member

HyperBrain commented Sep 19, 2017

So try to use just entry: slsw.lib.entries, remove the custom entry assembly and use the following for the json files:

// webpack config
module: {
    rules: [
      {
        test: /\.json$/,
        use: [
          {
            loader: 'file-loader',
            options: {}  
          }
        ]
      }
    ]
  }

This will bundle the json files and each require() works as expected. By default the loader renames the jsons (and the requires) to <hash>.json, but if you need the original filenames there is an option for that that you can supply to the loader.
And remember to do a npm install --save-dev file-loader

@rhlsthrm
Copy link
Author

Thank you so much for all the help! I am very close to having everything working. However now I am running into a couple more issues. I don't see either the models or the contracts appearing in the .webpack/ directory, so I am assuming they are not getting built.

How does the detection of the required files work? Does the file have to be explicitly imported or required?

In the case of the model, it is imported through Sequelize like so:

const User = sequelize.import('../../models/user.model.js')

For the contract, it is actually required by the code:

const vaultArtifacts = require('../build/contracts/Vault.json')

Is there anything else to do to make sure webpack is including the files properly?

@rhlsthrm
Copy link
Author

Never mind, I fixed that issue by manually adding the files to the entries list and now they show up in the build. Still hitting an error with my endpoint here:

Serverless: Error while loading key
[ 'TypeError: Path must be a string. Received undefined',
  'at assertPath (path.js:28:11)',
  'at Object.dirname (path.js:1345:5)',
  'at Sequelize.import (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/sequelize/lib/sequelize.js:371:31)',
  'at eval (webpack:///./functions/users/key.js?:28:38)',
  'at Object.<anonymous> (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/service/functions/users/key.js:132:1)',
  'at __webpack_require__ (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/service/functions/users/key.js:20:30)',
  'at /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/service/functions/users/key.js:63:18',
...

I'll keep digging into this more, I'm not sure why that is failing. If you have any ideas let me know. Once this is built successfully then I can close the issue.

@HyperBrain
Copy link
Member

I searched a bit about sequelize.import('../../models/user.model.js') and webpack. It seems that you have to require the models instead of using sequelize.import() with a filename. The problem is, that webpack will bundle the model js file -> so you should put the required model into sequelize.

@rhlsthrm
Copy link
Author

The problem is, that webpack will bundle the model js file -> so you should put the required model into sequelize.

Sorry can you elaborate on this? Not sure exactly what you mean.

Thank you again, you have truly been the most helpful open source dev I've worked with. I would love to donate to your project if you have a way to do that.

@HyperBrain
Copy link
Member

HyperBrain commented Sep 19, 2017

I mean that you should use require() to load the models (because they are bundled by webpack into the handler) and then use const model = sequelize.import('modelname', require('./path/to/models/modelname')); to load the model definition into sequelize.

This will let Webpack replace the require() call with the compiled version of the model instead of accessing local files.

As mentioned in the Import section here: http://docs.sequelizejs.com/manual/tutorial/models-definition.html

if you have a way to do that.

Sorry, but not yet ;-)

@rhlsthrm
Copy link
Author

rhlsthrm commented Sep 20, 2017

I tried this and unfortunately doesn't work... I'll keep poking on it.

EDIT: Also my error is different than what the documentation in that section is showing. My full stack trace is:

Serverless: Error while loading key
[ 'TypeError: Path must be a string. Received undefined',
  'at assertPath (path.js:28:11)',
  'at Object.dirname (path.js:1345:5)',
  'at Sequelize.import (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/sequelize/lib/sequelize.js:371:31)',
  'at Object.eval (webpack:///./functions/users/key.js?:29:38)',
  'at eval (webpack:///./functions/users/key.js?:75:30)',
  'at Object.<anonymous> (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/service/functions/users/key.js:139:1)',
  'at __webpack_require__ (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/service/functions/users/key.js:20:30)',
  'at /Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/service/functions/users/key.js:63:18',
  'at Object.<anonymous> (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/.webpack/service/functions/users/key.js:66:10)',
  'at Module._compile (module.js:569:30)',
  'at Object.Module._extensions..js (module.js:580:10)',
  'at Module.load (module.js:503:32)',
  'at tryModuleLoad (module.js:466:12)',
  'at Function.Module._load (module.js:458:3)',
  'at Module.require (module.js:513:17)',
  'at require (internal/module.js:11:18)',
  'at Object.createHandler (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/serverless-offline/src/functionHelper.js:35:21)',
  'at handler (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/serverless-offline/src/index.js:499:40)',
  'at Object.internals.handler (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/hapi/lib/handler.js:96:36)',
  'at request._protect.run (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/hapi/lib/handler.js:30:23)',
  'at module.exports.internals.Protect.internals.Protect.run (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/hapi/lib/protect.js:64:5)',
  'at exports.execute (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/hapi/lib/handler.js:24:22)',
  'at each (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/hapi/lib/request.js:384:16)',
  'at iterate (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/items/lib/index.js:36:13)',
  'at done (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/items/lib/index.js:28:25)',
  'at internals.Auth.payload (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/hapi/lib/auth.js:223:16)',
  'at each (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/hapi/lib/request.js:384:16)',
  'at iterate (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/items/lib/index.js:36:13)',
  'at done (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/items/lib/index.js:28:25)',
  'at onParsed (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/hapi/lib/route.js:402:20)',
  'at Subtext.parse (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/hapi/lib/route.js:423:20)',
  'at next (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/subtext/lib/index.js:45:26)',
  'at Wreck.read (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/subtext/lib/index.js:242:16)',
  'at finish (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/subtext/node_modules/wreck/lib/index.js:373:20)',
  'at wrapped (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/subtext/node_modules/hoek/lib/index.js:875:20)',
  'at module.exports.internals.Recorder.onReaderFinish (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/subtext/node_modules/wreck/lib/index.js:447:16)',
  'at Object.onceWrapper (events.js:314:30)',
  'at emitNone (events.js:110:20)',
  'at module.exports.internals.Recorder.emit (events.js:207:7)',
  'at finishMaybe (_stream_writable.js:587:14)',
  'at endWritable (_stream_writable.js:595:3)',
  'at module.exports.internals.Recorder.Writable.end (_stream_writable.js:546:5)',
  'at IncomingMessage.onend (_stream_readable.js:584:10)',
  'at Object.onceWrapper (events.js:314:30)',
  'at emitNone (events.js:110:20)',
  'at IncomingMessage.emit (events.js:207:7)',
  'at endReadableNT (_stream_readable.js:1045:12)',
  'at _combinedTickCallback (internal/process/next_tick.js:138:11)' ]

@rhlsthrm
Copy link
Author

I think my issue now is out of the scope of this issue, so I will close it.

To summarize:
We never found the root cause, the issue resolved itself when web3 got updated.

@HyperBrain
Copy link
Member

@rhlsthrm Nevertheless thanks for the good discussion. It might help others as starting point if they run into the same issues, So this thread has not been in vain 😃

@rhlsthrm
Copy link
Author

Definitely! It has been a great learning experience for me too. I plan on writing a blog article about my project, which will reference my learnings.

@rhlsthrm
Copy link
Author

Hi @HyperBrain, now that I am actually trying to use the module I'm running into more issues of course.

Here is an error I'm getting:

'Error: Cannot find module \'web3-requestManager\'',
  'at Function.Module._resolveFilename (module.js:485:15)',
  'at Function.Module._load (module.js:437:25)',
  'at Module.require (module.js:513:17)',
  'at require (internal/module.js:11:18)',
  'at Object.<anonymous> (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-core/src/index.js:26:22)',
  'at Module._compile (module.js:569:30)',
  'at Object.Module._extensions..js (module.js:580:10)',
  'at Module.load (module.js:503:32)',
  'at tryModuleLoad (module.js:466:12)',
  'at Function.Module._load (module.js:458:3)',
  'at Module.require (module.js:513:17)',
  'at require (internal/module.js:11:18)',
  'at Object.<anonymous> (/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/src/index.js:32:12)',
  'at Module._compile (module.js:569:30)',
  'at Object.Module._extensions..js (module.js:580:10)',
  'at Module.load (module.js:503:32)',
  'at tryModuleLoad (module.js:466:12)',
  'at Function.Module._load (module.js:458:3)',
  'at Module.require (module.js:513:17)',
  'at require (internal/module.js:11:18)',
  'at eval (webpack:///external_%22web3%22?:1:18)'

I did some research and found this thread: web3/web3.js#966

There's a snippet of how to get Webpack to work which says to add the following:

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,
]

Problem is, I'm not sure exactly how to refactor my webpack config to incorporate that.

I made my config the following:

var path = require('path')
const slsw = require('serverless-webpack')
var nodeExternals = require('webpack-node-externals')

var entries = slsw.lib.entries
console.log(entries)

const models = [
  './models/charge.model.js',
  './models/metrics.model.js',
  './models/user.model.js'
]
for (let i in models) {
  entries[models[i]] = models[i]
}

const contracts = [
  './build/contracts/Chargebackable.json',
  './build/contracts/ERC20.json',
  './build/contracts/ERC20Basic.json',
  './build/contracts/Owned.json',
  './build/contracts/Vault.json'
]

for (let i in contracts) {
  entries[contracts[i]] = contracts[i]
}
console.log(path.resolve(__dirname, '/node_modules/web3/packages'))
module.exports = {
  entry: entries,
  target: 'node',
  // Generate sourcemaps for proper error messages
  devtool: 'eval',
  externals: [nodeExternals()],
  // Run babel on all .js files and skip those in node_modules
  module: {
    rules: [
      {
        test: /\.js$/,
        use: [
          {
            loader: 'babel-loader'
          }
        ],
        include: __dirname,
        exclude: /node_modules/
      },
      {
        test: /\.(json)$/,
        use: [
          {
            loader: 'file-loader'
          }
        ],
        include: __dirname,
        exclude: /node_modules/
      }
    ]
  },
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js'
  },
  resolve: {
    modules: ['./node_modules', './node_modules/web3/packages']
  }
}

This did not fix the error. Can you tell me if my syntax is correct, and how I can verify that the modules are getting included?

@rhlsthrm rhlsthrm reopened this Sep 21, 2017
@HyperBrain
Copy link
Member

Verification is quite easy: Run serverless package and check the zip files created in .serverless if they contain the modules.

For the config ... I'll try to come up with a solution after reading the thread.

@HyperBrain
Copy link
Member

Ok. I think the error is, that the snippet above adds all node_modules folders under the separate web3/packages and not the folder itself. So you have to add the whole mechanism in your config like this:

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

// is directory
const isDirectory = source => lstatSync(source).isDirectory();
// get directories
const getDirectories = source => readdirSync(source).map(name => path.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 => path.join(m, 'node_modules')));

// Rest of the webpack config

Then the node_modules variable should contain all separate node_modules folders from web3.

Now add them to your resolve section:

resolve: {
    modules: node_modules
  }

However I do not know if this will work right away, because I never tested module resolution throughout multiple module folder paths. But it's an interesting experiment.

@rhlsthrm
Copy link
Author

Same error :(. Here is my new config:

var path = require('path')
const slsw = require('serverless-webpack')
var nodeExternals = require('webpack-node-externals')

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

// is directory
const isDirectory = source => lstatSync(source).isDirectory()
// get directories
const getDirectories = source =>
  readdirSync(source).map(name => path.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 => path.join(m, 'node_modules')))

var entries = slsw.lib.entries

const models = [
  './models/charge.model.js',
  './models/metrics.model.js',
  './models/user.model.js'
]
for (let i in models) {
  entries[models[i]] = models[i]
}

const contracts = [
  './build/contracts/Chargebackable.json',
  './build/contracts/ERC20.json',
  './build/contracts/ERC20Basic.json',
  './build/contracts/Owned.json',
  './build/contracts/Vault.json'
]

for (let i in contracts) {
  entries[contracts[i]] = contracts[i]
}
console.log(path.resolve(__dirname, '/node_modules/web3/packages'))
module.exports = {
  entry: entries,
  target: 'node',
  // Generate sourcemaps for proper error messages
  devtool: 'eval',
  externals: [nodeExternals()],
  // Run babel on all .js files and skip those in node_modules
  module: {
    rules: [
      {
        test: /\.js$/,
        use: [
          {
            loader: 'babel-loader'
          }
        ],
        include: __dirname,
        exclude: /node_modules/
      },
      {
        test: /\.(json)$/,
        use: [
          {
            loader: 'file-loader'
          }
        ],
        include: __dirname,
        exclude: /node_modules/
      }
    ]
  },
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js'
  },
  resolve: {
    modules: nodeModules
  }
}

I believe you meant to type nodeModules instead of node_modules in the resolve section, correct?

Thanks again, I really hope we can get this resolved soon, I feel like it's close.

@HyperBrain
Copy link
Member

Yes I meant nodeModules :) Can you disable node-externals and try to let webpack bundle just everything for testing? If the error then still appears - there has been a complementary PR merged 6 days ago in the web3 repo that might be needed: web3/web3.js#1006

So just comment out the externals: line and tell me what happened.

@rhlsthrm
Copy link
Author

Interesting, a bunch more errors come up:

WARNING in ./node_modules/sequelize/lib/dialects/postgres/connection-manager.js
21:16-59 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/sequelize/lib/dialects/mssql/connection-manager.js
21:19-62 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/sequelize/lib/dialects/sqlite/connection-manager.js
25:19-62 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/sequelize/lib/dialects/mysql/connection-manager.js
31:19-62 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/sequelize/lib/sequelize.js
377:61-74 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/sequelize/lib/dialects/mysql/connection-manager.js
Module not found: Error: Can't resolve 'mysql2' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/sequelize/lib/dialects/mysql'
 @ ./node_modules/sequelize/lib/dialects/mysql/connection-manager.js 33:19-36
 @ ./node_modules/sequelize/lib/dialects/mysql/index.js
 @ ./node_modules/sequelize/lib/sequelize.js
 @ ./node_modules/sequelize/index.js
 @ ./models/user.model.js

WARNING in ./node_modules/sequelize/lib/dialects/sqlite/connection-manager.js
Module not found: Error: Can't resolve 'sqlite3' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/sequelize/lib/dialects/sqlite'
 @ ./node_modules/sequelize/lib/dialects/sqlite/connection-manager.js 27:19-37
 @ ./node_modules/sequelize/lib/dialects/sqlite/index.js
 @ ./node_modules/sequelize/lib/sequelize.js
 @ ./node_modules/sequelize/index.js
 @ ./models/user.model.js

WARNING in ./node_modules/sequelize/lib/dialects/mssql/connection-manager.js
Module not found: Error: Can't resolve 'tedious' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/sequelize/lib/dialects/mssql'
 @ ./node_modules/sequelize/lib/dialects/mssql/connection-manager.js 23:19-37
 @ ./node_modules/sequelize/lib/dialects/mssql/index.js
 @ ./node_modules/sequelize/lib/sequelize.js
 @ ./node_modules/sequelize/index.js
 @ ./models/user.model.js

ERROR in ./node_modules/web3/packages/web3-utils/src/utils.js
Module not found: Error: Can't resolve 'eth-lib/src/hash' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-utils/src'
 @ ./node_modules/web3/packages/web3-utils/src/utils.js 27:11-38
 @ ./node_modules/web3/packages/web3-utils/src/index.js
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-utils/src/index.js
Module not found: Error: Can't resolve 'ethjs-unit' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-utils/src'
 @ ./node_modules/web3/packages/web3-utils/src/index.js 26:16-37
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/sequelize/lib/dialects/postgres/hstore.js
Module not found: Error: Can't resolve 'pg-hstore' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/sequelize/lib/dialects/postgres'
 @ ./node_modules/sequelize/lib/dialects/postgres/hstore.js 3:15-35
 @ ./node_modules/sequelize/lib/dialects/postgres/data-types.js
 @ ./node_modules/sequelize/lib/data-types.js
 @ ./node_modules/sequelize/lib/sequelize.js
 @ ./node_modules/sequelize/index.js
 @ ./models/user.model.js

ERROR in ./node_modules/pg/lib/native/client.js
Module not found: Error: Can't resolve 'pg-native' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/pg/lib/native'
 @ ./node_modules/pg/lib/native/client.js 10:13-33
 @ ./node_modules/pg/lib/native/index.js
 @ ./node_modules/pg/lib/index.js
 @ ./node_modules/sequelize/lib/dialects/postgres/connection-manager.js
 @ ./node_modules/sequelize/lib/dialects/postgres/index.js
 @ ./node_modules/sequelize/lib/sequelize.js
 @ ./node_modules/sequelize/index.js
 @ ./models/user.model.js

ERROR in ./node_modules/web3/packages/web3-utils/src/index.js
Module not found: Error: Can't resolve 'randomhex' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-utils/src'
 @ ./node_modules/web3/packages/web3-utils/src/index.js 29:16-36
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-bzz/src/index.js
Module not found: Error: Can't resolve 'swarm-js' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-bzz/src'
 @ ./node_modules/web3/packages/web3-bzz/src/index.js 26:12-31
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/sequelize/lib/dialects/mssql/query.js
Module not found: Error: Can't resolve 'tedious' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/sequelize/lib/dialects/mssql'
 @ ./node_modules/sequelize/lib/dialects/mssql/query.js 10:14-32
 @ ./node_modules/sequelize/lib/dialects/mssql/index.js
 @ ./node_modules/sequelize/lib/sequelize.js
 @ ./node_modules/sequelize/index.js
 @ ./models/user.model.js

ERROR in ./node_modules/web3/packages/web3-eth-personal/src/index.js
Module not found: Error: Can't resolve 'web3-core' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth-personal/src'
 @ ./node_modules/web3/packages/web3-eth-personal/src/index.js 25:11-31
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-eth/src/index.js
Module not found: Error: Can't resolve 'web3-core' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth/src'
 @ ./node_modules/web3/packages/web3-eth/src/index.js 26:11-31
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-net/src/index.js
Module not found: Error: Can't resolve 'web3-core' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-net/src'
 @ ./node_modules/web3/packages/web3-net/src/index.js 25:11-31
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-shh/src/index.js
Module not found: Error: Can't resolve 'web3-core' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-shh/src'
 @ ./node_modules/web3/packages/web3-shh/src/index.js 25:11-31
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-core/src/extend.js
Module not found: Error: Can't resolve 'web3-core-helpers' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-core/src'
 @ ./node_modules/web3/packages/web3-core/src/extend.js 26:17-45
 @ ./node_modules/web3/packages/web3-core/src/index.js
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-eth-personal/src/index.js
Module not found: Error: Can't resolve 'web3-core-helpers' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth-personal/src'
 @ ./node_modules/web3/packages/web3-eth-personal/src/index.js 30:17-45
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-eth/src/index.js
Module not found: Error: Can't resolve 'web3-core-helpers' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth/src'
 @ ./node_modules/web3/packages/web3-eth/src/index.js 27:14-42
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-core/src/extend.js
Module not found: Error: Can't resolve 'web3-core-method' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-core/src'
 @ ./node_modules/web3/packages/web3-core/src/extend.js 27:13-40
 @ ./node_modules/web3/packages/web3-core/src/index.js
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-eth-personal/src/index.js
Module not found: Error: Can't resolve 'web3-core-method' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth-personal/src'
 @ ./node_modules/web3/packages/web3-eth-personal/src/index.js 26:13-40
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-eth/src/index.js
Module not found: Error: Can't resolve 'web3-core-method' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth/src'
 @ ./node_modules/web3/packages/web3-eth/src/index.js 29:13-40
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-net/src/index.js
Module not found: Error: Can't resolve 'web3-core-method' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-net/src'
 @ ./node_modules/web3/packages/web3-net/src/index.js 26:13-40
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-shh/src/index.js
Module not found: Error: Can't resolve 'web3-core-method' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-shh/src'
 @ ./node_modules/web3/packages/web3-shh/src/index.js 27:13-40
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-eth/src/index.js
Module not found: Error: Can't resolve 'web3-core-subscriptions' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth/src'
 @ ./node_modules/web3/packages/web3-eth/src/index.js 28:20-54
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-shh/src/index.js
Module not found: Error: Can't resolve 'web3-core-subscriptions' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-shh/src'
 @ ./node_modules/web3/packages/web3-shh/src/index.js 26:20-54
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-eth/src/index.js
Module not found: Error: Can't resolve 'web3-eth-abi' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth/src'
 @ ./node_modules/web3/packages/web3-eth/src/index.js 37:10-33
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-eth/src/index.js
Module not found: Error: Can't resolve 'web3-eth-accounts' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth/src'
 @ ./node_modules/web3/packages/web3-eth/src/index.js 36:15-43
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-eth/src/index.js
Module not found: Error: Can't resolve 'web3-eth-contract' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth/src'
 @ ./node_modules/web3/packages/web3-eth/src/index.js 34:15-43
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-eth/src/index.js
Module not found: Error: Can't resolve 'web3-eth-iban' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth/src'
 @ ./node_modules/web3/packages/web3-eth/src/index.js 35:11-35
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-eth/src/index.js
Module not found: Error: Can't resolve 'web3-eth-personal' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth/src'
 @ ./node_modules/web3/packages/web3-eth/src/index.js 33:15-43
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-eth-personal/src/index.js
Module not found: Error: Can't resolve 'web3-net' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth-personal/src'
 @ ./node_modules/web3/packages/web3-eth-personal/src/index.js 28:10-29
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-eth/src/index.js
Module not found: Error: Can't resolve 'web3-net' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth/src'
 @ ./node_modules/web3/packages/web3-eth/src/index.js 31:10-29
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-shh/src/index.js
Module not found: Error: Can't resolve 'web3-net' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-shh/src'
 @ ./node_modules/web3/packages/web3-shh/src/index.js 29:10-29
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-core/src/index.js
Module not found: Error: Can't resolve 'web3-requestManager' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-core/src'
 @ ./node_modules/web3/packages/web3-core/src/index.js 26:21-51
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-core/src/extend.js
Module not found: Error: Can't resolve 'web3-utils' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-core/src'
 @ ./node_modules/web3/packages/web3-core/src/extend.js 28:12-33
 @ ./node_modules/web3/packages/web3-core/src/index.js
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-eth-personal/src/index.js
Module not found: Error: Can't resolve 'web3-utils' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth-personal/src'
 @ ./node_modules/web3/packages/web3-eth-personal/src/index.js 27:12-33
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-eth/src/index.js
Module not found: Error: Can't resolve 'web3-utils' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth/src'
 @ ./node_modules/web3/packages/web3-eth/src/index.js 30:12-33
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

ERROR in ./node_modules/web3/packages/web3-net/src/index.js
Module not found: Error: Can't resolve 'web3-utils' in '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-net/src'
 @ ./node_modules/web3/packages/web3-net/src/index.js 27:12-33
 @ ./node_modules/web3/src/index.js
 @ ./lib/web3.js
 @ ./lib/Vault.js
 @ ./functions/vault/getOwner.js

Interesting, seems like it's now seeing what it needs but unable to find them?

@HyperBrain
Copy link
Member

HyperBrain commented Sep 21, 2017

That points to the missing PR I mentioned before (according to the thread it is needed additionally to the fix you already made). But I agree, you're nearly there.
Maybe you can install the PR target branch from web3 (ethereum:1.0) and just test if that fixes the problem. Otherwise dump the content of nodeModules and see if all the module directories are in there.

... and: this is somehow a can of worms 😄

@rhlsthrm
Copy link
Author

Contents of nodeModules:

[ '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/node_modules/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-bzz/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-core/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-core-helpers/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-core-method/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-core-promiEvent/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-core-requestManager/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-core-subscriptions/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth-abi/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth-accounts/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth-contract/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth-iban/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-eth-personal/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-net/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-providers-http/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-providers-ipc/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-providers-ws/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-shh/node_modules',
  '/Users/Rahul/Desktop/connext/ConnextAPI/src/server/node_modules/web3/packages/web3-utils/node_modules' ]

Looks like the right stuff is in there. I'll try with the latest PR. I might not get to it today, but I'll update when I find out more.

@rhlsthrm
Copy link
Author

I'm looking back on this whole journey and asking myself why I am going through the trouble of using Webpack to begin with in this project. The reason for me to go down this route initially was so that I could use Babel and transpile ES2017 syntax to work in the Serverless Node environments. If I cut Webpack out of the picture and use raw Node 6 syntax, I will most likely save myself this type of trouble, which isn't productive to me right now.

Is there any other reason you see to continue trying to get the transpilation to work?

@HyperBrain
Copy link
Member

Not really anything important 🤔 . If you have plain Node 6 compatible code you'd not need a transpiler. Despite of the advanced packagin that webpack/the plugin offer, there is not really a need to integrate it - especially with web3, which has shown that it itself is not yet 100% compatible with webpack (see the PR and the thread).
It would be interesting to give it a further try (1) if you have a lot of spare time and (2) if the threads in the web3 repo confirm proper solutions and configs that make it work.

So, just try it with a pure SLS deployment for now. It would be also interesting, if the native SLS packaging can correctly package the modules.

@rhlsthrm
Copy link
Author

Yes, I think I should give that a try. I will come back to this issue if I run into it again.

@HyperBrain
Copy link
Member

Ok. Then I'll close it (again 😄 ) for now. We can reopen it as soon as there are further tries to get it working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants