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

New AWS Lambda Example error: Failure: serverlessExpress is not a function #804

Closed
4 of 10 tasks
avery100 opened this issue Feb 19, 2021 · 6 comments · Fixed by #806
Closed
4 of 10 tasks

New AWS Lambda Example error: Failure: serverlessExpress is not a function #804

avery100 opened this issue Feb 19, 2021 · 6 comments · Fixed by #806
Labels
area:examples issues related to example or sample code bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented

Comments

@avery100
Copy link

avery100 commented Feb 19, 2021

Description

Sorry about the spam - Github server was spasming when i hit submit and it hung, i must have hit refresh. Apologies.

Due to the new guidelines about the deprecation of aws-serverless-express - i've updated my code to the new app.js example, as well as updated @slack/bolt to 3.2.0. I have the latest @vendia/serverless-express@3.4.0. Here is my npm list of serverless - (does it need to **not** be a dependency of aws-serverless-express@3.4.0 ?)
_user$ npm list @vendia/serverless-express
myl-app@1.0.0 /Library/WebServer/Documents/App/my-app
└─┬ aws-serverless-express@3.4.0
  └── @vendia/serverless-express@3.4.0_ 

-- running my app code that worked before the updgrade, i receive this error:

**offline: POST /slack/events (λ: slack)
offline: Failure: serverlessExpress is not a function
TypeError: serverlessExpress is not a function
    at Object.<anonymous> (/Library/WebServer/Documents/App/my-app/app.js:60:26)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at /Library/WebServer/Documents/App/my-app/node_modules/serverless-offline/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js:145:133
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at InProcessRunner.run (/Library/WebServer/Documents/App/my-app/node_modules/serverless-offline/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js:145:9)**

Thinking that it was my code that caused the issue, i just ran the exact code from here: https://github.com/slackapi/bolt-js/blob/main/examples/deploy-aws-lambda/app.js

Still getting the same error.

Here is the serverless local app start:

_Serverless: Deprecation warning: Starting with next major version, default value of provider.lambdaHashingVersion will be equal to "20201221"
            More Info: https://www.serverless.com/framework/docs/deprecations/#LAMBDA_HASHING_VERSION_V2
Serverless: Deprecation warning: Starting with next major version, API Gateway naming will be changed from "{stage}-{service}" to "{service}-{stage}".
            Set "provider.apiGateway.shouldStartNameWithService" to "true" to adapt to the new behavior now.
            More Info: https://www.serverless.com/framework/docs/deprecations/#AWS_API_GATEWAY_NAME_STARTING_WITH_SERVICE
offline: Starting Offline: dev/us-east-1.
offline: Offline [http for lambda] listening on http://localhost:3002
offline: Function names exposed for local invocation by aws-sdk:
           * slack: serverless-bolt-js-dev-slack

   ┌─────────────────────────────────────────────────────────────────────────┐
   │                                                                         │
   │   POST | http://localhost:3000/slack/events                             │
   │   POST | http://localhost:3000/2015-03-31/functions/slack/invocations   │
   │   GET  | http://localhost:3000/slack/install                            │
   │   POST | http://localhost:3000/2015-03-31/functions/slack/invocations   │
   │   GET  | http://localhost:3000/slack/oauth_redirect                     │
   │   POST | http://localhost:3000/2015-03-31/functions/slack/invocations   │
   │                                                                         │
   └─────────────────────────────────────────────────────────────────────────┘

offline: [HTTP] server ready: http://localhost:3000 🚀
offline: 
offline: Enter "rp" to replay the last request_

Your help is greatly appreciated. Thank you very much for your attention :-)
Andy

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • example code related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

package version:
@slack/bolt 3.2.0
@vendia/serverless-express@3.4.0

node version: v12.18.3

OS version(s): mac os sierra 10.12.6 (16G2136)

Steps to reproduce:

1.Follow the steps here exactly: https://slack.dev/bolt-js/deployments/aws-lambda
2.
3.

Expected result:

Local app to process Slack request / input

Actual result:

Error processing the Slack request / input

offline: POST /slack/events (λ: slack)
offline: Failure: serverlessExpress is not a function
TypeError: serverlessExpress is not a function
    at Object.<anonymous> (/Library/WebServer/Documents/HeyAxl/hey-axl-app/app.js:60:26)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at /Library/WebServer/Documents/HeyAxl/hey-axl-app/node_modules/serverless-offline/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js:145:133
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at InProcessRunner.run (/Library/WebServer/Documents/HeyAxl/hey-axl-app/node_modules/serverless-offline/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js:145:9)

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

@avery100
Copy link
Author

avery100 commented Feb 19, 2021

screen_serverlessExpress2

Noticed this. Following the first guidance (Try npm i --save-dev @types/vendia__serverless-express if it exists) didn't help. Trying this now: add a new declaration (.d.ts) file containing `declare module '@vendia/serverless-express';

@avery100
Copy link
Author

So i added a global.d.ts file in the root of my project and added: declare module '@vendia/serverless-express'; The popup issue disappeared from VS Code but the original error still gets thrown (Failure: serverlessExpress is not a function)

@mwbrooks mwbrooks added area:examples issues related to example or sample code bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented and removed untriaged labels Feb 19, 2021
@mwbrooks
Copy link
Member

Hey @avery100, thanks for raising this issue. Truthfully, I only looked over the example code and referenced it against the documentation. I didn't deploy it and double-check that it worked. The changes looked minor 😳

I'll look into reproducing the issue and see if I can find a solution.

I appreciate the updates as you explore it as well, so please let me know if you make some headway!

@mwbrooks
Copy link
Member

@avery100 I was able to resolve the issue by updating package.json to use the latest @vendia/serverless-express (4.3.2).

Getting there involved a few steps. First, I noticed that our current example still uses the original aws-serverless-express. When I tried to npm install @vendia/serverless-express, it installed an older ^3.0.0 for some reason. Unfortunately, this version uses the old aws-serverless-express (.createServer and .proxy). When I updated to the latest version and the example worked fine.

Would you mind confirming by upgrading to the latest version as well?

    "@vendia/serverless-express": "^4.3.2"

@avery100
Copy link
Author

Hi @mwbrooks, I had to finish my code for the night and so i reverted to the deprecated aws-serverless-express version of my code - got it all working that way for now. I have to switch hats and work on another app - i will try to confirm tomorrow or the day after. Thank you so much for figuring this out!

mwbrooks added a commit to mwbrooks/bolt-js that referenced this issue Feb 19, 2021
mwbrooks added a commit to mwbrooks/bolt-js that referenced this issue Feb 19, 2021
mwbrooks added a commit that referenced this issue Feb 19, 2021
* [#804] Fix AWS Lambda deploy guide using @vendia/serverless-express
* [#804] Update ja_aws-lambda.md
@mwbrooks
Copy link
Member

@avery100 No worries and thanks for taking the time to help us confirm the fix! 👊🏻 I've merged PR #806, which updates the documentation and example app. I tested it locally and on AWS Lambda.

If you've reverted to the older approach, then you should be able to use @vendia/serverless-express@3.x.x because it uses the original .createServer and .proxy interface.

Otherwise, you can update your code to use the modern approach, which requires @vendia/serverless-express@4.x.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:examples issues related to example or sample code bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants