serverless-heaven / serverless-webpack

Serverless plugin to bundle your lambdas with Webpack
MIT License
1.72k stars 417 forks source link

Error with multiple runtimes #644

Closed dennistruemper closed 3 years ago

dennistruemper commented 4 years ago

This is a Bug Report

Description

If you try to add a second runtime (in my example golang) for a new Lambda, you get following error: TypeError [ERR_INVALID_ARG_TYPE]: The "to" argument must be of type string. Received undefined in node_modules/serverless-webpack/lib/validate.js:199:36 because the plugin tries to use the golang lambda to do webpack stuff.

If you just filter the functions for runtimes starting with node fixes the problem.

//  Lookup associated Serverless functions
        const allEntryFunctions = _.map(
          this.serverless.service.getAllFunctions().map(
            funcName =>this.serverless.service.getFunction(funcName) )
            .filter(func => func.runtime.startsWith('node')), func => {
          const handler = func.handler;
          const handlerFile = path.relative('.', getHandlerFile(handler));
          const runtime = func.runtime
          return {
            handlerFile,
            funcName: func.name,
            func,
          };
        });

Additional Data

dennistruemper commented 4 years ago

My configuration hat no runtime set in provider package, every function had it set individually. My solution crashes if provider runtime is set. So it is not a solution. I tried to fix this for all cases, but then I started to see, that every provider has to be checked. I will just fix my special case and link in here as inspiration for someone to fix it completely.