Search code examples
javascriptserverless-framework

Serverless framework: All of a sudden receiving "ERROR TypeError: e is not a function" after deployment of service


Dear Stackoverflow community,

I am using the serverless framework to deploy my JS services to AWS. It always worked perfectly but since today, after deploying a little change to one of my functions' code, I am receiving the following error when calling any function in the service:

ERROR   TypeError: e is not a function
    at Runtime.handler (/var/task/serverless_sdk/index.js:9:137343)
    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)

I do not understand where this comes from. I did not change the serverless.yml at all, also I did not change any basics of the function code (only a small change in an SQL statement, has nothing to do with the JavaScript code at all). I have read the following question Serverless framework TypeError: e is not a function but nothing described there fits to my situation.

Some more context information:

  • I have a microservices architecture with multiple services being deployed separately via serverless framework
  • At the moment only one of my services shows this problem. First I had only deployed one function via sls deploy -f ... - after the deployment, the error described above popped up for that one function. Then, for testing purposes, I deployed the whole service again via sls deploy. Now all functions in the service raise the error described above when being invoked remotely (either via sls invoke -f ... or when calling the functions via the API).
  • The error does not occur when calling the functions locally via sls invoke local -f ....
  • Also I tried to redeploy a different service to make sure it is not a general serverless issue - after redeploying the other service, the functions in that other service can be called without any problem. The error does not occur here.
  • I tried to make a diff of the two serverless.yml files and also of the function files of the different services just to make sure I did not accidentially include some typing error but everything looks perfectly fine.

Does anybody have an idea where this might come from all of a sudden?

EDIT 1: I have also already upgraded the serverless framework - did not help

EDIT 2: The strange thing is that this problem occured all of a sudden while I had not changed any code - that's why I did not think posting any code would help. Now I am also experiencing this problem in further services that I want to deploy. I cannot deploy any function any more. As soon as I deploy a single function or a full service that did not have the issue before, the issue arises there as well. @PatrykMilewski: I checked the Lambda console and what I realized is that after deploying, the file that contains my function ("function.js") IS EMPTY whereas for services that had been deployed previously, the file IS NOT EMPTY. I would assume this might be the reason for the error message. Could this be caused by a bug in the serverless framework?

EDIT 3: I just remembered that I recently upgraded Mac OS to the latest version including new XCode Command Line Tools v13. From a time perspective, this could coincide with the issue popping up - could this be related to the problem?

EDIT 4: Some more environment information:

From my operating system:

ProductName:    macOS
ProductVersion: 11.6
BuildVersion:   20G165

From Serverless console output:

Operating System:          darwin
Node Version:              16.10.0
Framework Version:         2.10.0 (local)
Plugin Version:            4.1.1
SDK Version:               2.3.2
Components Version:        3.3.0

Solution

  • Together with the very helpful support from the serverless team, I was able to resolve the issue. The reason for the issue actually was an outdated serverless version which I was not aware of. Usually I use yarn upgrade to upgrade all of my packages regularly. But in this case there was a dependency which forced serverless to stay on an outdated version. Only after proactively forcing serverless to upgrade to the latest version using yarn upgrade serverless@2.61.0 and then afterwards calling once more yarn upgrade to also make the dependent packages based upon the new serverless version, I was able to upgrade serverless and its dependencies. After that, I deployed my services again and the error described above disappeared when calling my functions remotely.

    I hope this also will help someone else who comes across this issue.