Module not found when building netlify-lambda

I’ve been trying to build my express application into lambda functions - It has been written using es6 (babel7). Everything runs smoothly when I run the app and run tests, but when it comes to build the functions with the command netlify-lambda build src it says some modules are not found. I’ve tried to delete node_modules and package-lock.json and tried to npm install again (didn’t work), also tried with yarn - same result

ModuleNotFoundError: Module not found: Error: Can't resolve 'electron' in '/apps/my-app/node_modules/swarm-js/node_modules/got'
    at factory.create (/apps/my-app/node_modules/webpack/lib/Compilation.js:925:10)
    at factory (/apps/my-app/node_modules/webpack/lib/NormalModuleFactory.js:401:22)
    at resolver (/apps/my-app/node_modules/webpack/lib/NormalModuleFactory.js:130:21)
    at asyncLib.parallel (/apps/my-app/node_modules/webpack/lib/NormalModuleFactory.js:224:22)
    at /apps/my-app/node_modules/neo-async/async.js:2830:7
    at /apps/my-app/node_modules/neo-async/async.js:6877:13
    at normalResolver.resolve (/apps/my-app/node_modules/webpack/lib/NormalModuleFactory.js:214:25)
    at doResolve (/apps/my-app/node_modules/enhanced-resolve/lib/Resolver.js:213:14)
    at hook.callAsync (/apps/my-app/node_modules/enhanced-resolve/lib/Resolver.js:285:5)
    at _fn0 (eval at create (/apps/my-app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
resolve 'electron' in '/apps/my-app/node_modules/swarm-js/node_modules/got'
  Parsed request is a module
  using description file: /apps/my-app/node_modules/swarm-js/node_modules/got/package.json (relative path: .)
    resolve as module
      /apps/my-app/node_modules/swarm-js/node_modules/got/node_modules doesn't exist or is not a directory
      /apps/my-app/node_modules/swarm-js/node_modules/node_modules doesn't exist or is not a directory
      /apps/my-app/node_modules/node_modules doesn't exist or is not a directory
      /apps/my-app't exist or is not a directory
      /apps/my-app exist or is not a directory
      /apps/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      /Users/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory

This is local, so I have don’t have any instance - yet

Hi @cbrzn, Do you have binary as a dependency? If so you can’t bundle that, you can only bundle text based files like js files. If a one of the modules is a C++ binary then it won’t bundle. I don’t know if that’s the case here, but I see a reference to electron in your log.

Have you tried just using zip it and ship it by installing the dependencies and deploying that code as is? We’ll then zip the js file and it’s dependencies without bundling. You’ll have to transpile to the JS supported by the node version you’re using in your function though, which means ES7 is not supported.