serverless-heaven / serverless-webpack

Serverless plugin to bundle your lambdas with Webpack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

serverless-webpack is not compatible with new function level individual packaging

deathweaselx86 opened this issue · comments

I am using serverless 1.11.0 with the new function level individual packaging feature.
Here is a piece of my serverless.yml.

request:
   handler: request.handler
   package:
       individually: true
       include:
          - request.js

When I sls deploy, I get this error.

Serverless: Packaging service...

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

     ENOENT: no such file or directory, open '/Users/deathweasel/Documents/repos/****/****/.webpack/.serverless/service-functionname.zip'****

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

  Stack Trace --------------------------------------------
Error: ENOENT: no such file or directory, open '/Users/deathweasel/Documents/repos/****/****/.webpack/.serverless/service-functionname.zip'****
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at Object.fs.readFileSync (fs.js:508:33)
    at AwsCompileFunctions.compileFunction (/Users/deathweasel/Documents/repos/****/****/node_modules/serverless/lib/plugins/aws/deploy/compile/functions/index.js:176:24)
    at serverless.service.getAllFunctions.forEach (/Users/deathweasel/Documents/repos/****/****/node_modules/serverless/lib/plugins/aws/deploy/compile/functions/index.js:218:39)
    at Array.forEach (native)
    at AwsCompileFunctions.compileFunctions (/Users/deathweasel/Documents/repos/****/****/node_modules/serverless/lib/plugins/aws/deploy/compile/functions/index.js:218:8)
    at BbPromise.reduce (/Users/deathweasel/Documents/repos/****/****/node_modules/serverless/lib/classes/PluginManager.js:210:55)
From previous event:
    at PluginManager.invoke (/Users/deathweasel/Documents/repos/****/****/node_modules/serverless/lib/classes/PluginManager.js:210:22)
    at PluginManager.run (/Users/deathweasel/Documents/repos/****/****/node_modules/serverless/lib/classes/PluginManager.js:225:17)
    at Serverless.run (/Users/deathweasel/Documents/repos/****/****/node_modules/serverless/lib/Serverless.js:97:31)
    at serverless.init.then (/Users/deathweasel/Documents/repos/****/****/node_modules/serverless/bin/serverless:23:50)

I did a quick examination of the code and it looks like serverless-webpack doesn't examine that setting at all.

A lot of things happened within Serverless from 1.11 to 1.16. Can anyone confirm this issue and post the error again with a recent version of Serverless? Not sure if this is a feature or bug.

I tested the package: individually: true setting at the top level of the serverless.yml.
The expected behaviour is, that after a serverless package one ZIP file for each function should be found in the package artifact directory, each with a different size (as webpack should generate separate bundles for each function handler).

But the actual result is, that there are ZIP files for each function handler, but all ZIPs are identical. In fact using the individually switch just led to multiplying the upload size by the number of lambda functions.

My conclusion is, that there are multiple issues with individual packaging that have to be solved. It has to work with all configurations, regardless where the flag is specified.

A proper solution should configure the bundles/chunks for each individual function and set the entry points automatically. An idea of automated entry point generation can be found in #130 (deploy function support) that will need a similar packaging algorithm - somehow the packaging in there can be seen as a subset of individual packaging of multiple functions in a service.

@HyperBrain I've made a project that reproduces this bug for me (works in serverless v1.17.0 but fails after updating to serverless v 1.18.0)

https://github.com/dashmug/sls-webpack-bug-120-repro

My suspicion is that the data structure in serverless v1.18.0 has changed.

I will check this again after I merged #159 which fixes an artifact path issue when individual packaging is used.

I implemented the support of the service wide package: individually: true. It is available in the v3.0.0-individual-packaging branch. Can you test, if the branch works, if you set the flag at service level?
Please comment the results in #177 .

The implementation uses the changed structures in 1.17 and 1.18 (the internal artifact settings changed within Serverless, which causes the problems between the two versions).

@HyperBrain
It has been working for me since serverless-webpack v2.1.0. See the recent commits on https://github.com/dashmug/sls-webpack-bug-120-repro.

Great job on fixing that.