Serverless-offline: Generic error when using the latest version

Created on 15 May 2019  ยท  9Comments  ยท  Source: dherault/serverless-offline

I have been using serverless-offline for many months on my current project. My AWS setup has a react frontend with https enabled. Everything still worked today, but then I did a full re-build by deleting node_modules. Suddenly I was getting this error on the command line:

sessionID: SIJ0soLd7YGQdew5I3h5BHnzlyOVIccd
Debug: internal, implementation, error 
    TypeError: Uncaught error: Cannot read property 'done' of undefined
    at createLambdaContext (/home/max/Documents/code/ark/trinity/nextjs/node_modules/serverless-offline/src/index.js:671:44)
    at process.nextTick (/home/max/Documents/code/ark/trinity/nextjs/node_modules/serverless-http/lib/dispatch.js:7:9)
    at _combinedTickCallback (internal/process/next_tick.js:132:7)
    at process._tickDomainCallback (internal/process/next_tick.js:219:9)

Looking at the source code at that line, it seems like maybe the request is empty. The error is a generic error about promises, I think. After some trial and error I found that downgrading the version of serverless-offline fixes the problem.

My old package.json:

"serverless-offline": "^4.0.0",

Downgrade to 4.10.0 and it will work again:

"serverless-offline": "=4.10.0",


Full logs from building to the error:

(09:11:57)[max@think nextjs]$ yarn; node-prune; yarn build; yarn devel
yarn install v1.12.3
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "@material-ui/styles > [email protected]" has incorrect peer dependency "[email protected]".
warning "@zeit/next-css > [email protected]" has unmet peer dependency "webpack@^4.0.0".
warning "@zeit/next-css > [email protected]" has unmet peer dependency "webpack@^4.4.0".
warning "@zeit/next-sass > [email protected]" has unmet peer dependency "webpack@^2.0.0 || >= 3.0.0-rc.0 || ^3.0.0".
warning "next-images > [email protected]" has unmet peer dependency "webpack@^4.0.0".
warning "next-images > [email protected]" has unmet peer dependency "webpack@^3.0.0 || ^4.0.0".
warning " > [email protected]" has incorrect peer dependency "react@>= 16.8".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 9.39s.

     files total 40,930
   files removed 12,174
    size removed 63 MB
        duration 326ms

yarn run v1.12.3
$ rm -rf .next && next build
Creating an optimized production build ...

Using external babel configuration
Location: "/home/max/Documents/code/ark/trinity/nextjs/.babelrc"
Compiled successfully.

โ”Œ /
โ”œ /_app
โ”œ /_document
โ”œ /_error
โ”œ /about
โ”œ /additem
โ”œ /archive
โ”œ /cart
โ”œ /help
โ”œ /history
โ”œ /item
โ”œ /login
โ”œ /manage
โ”œ /profile
โ”” /shop

Done in 52.04s.
yarn run v1.12.3
$ yarn prod --stage development
$ NODE_ENV=production yarn offline --port=3000 --host=0.0.0.0 --stage development
$ sls offline start --port=3000 --host=0.0.0.0 --stage development
Serverless: Starting Offline: development/us-east-1.

Serverless: Routes for imageWatermark:
Serverless: (none)

Serverless: Routes for getCounts:
Serverless: POST /counts

Serverless: Routes for getCartGuest:
Serverless: POST /get_cart_guest

Serverless: Routes for getCartAuth:
Serverless: POST /get_cart_auth
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type

Serverless: Routes for checkUserDb:
Serverless: POST /checkUserDb
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type

Serverless: Routes for imageCleanup:
Serverless: (none)

Serverless: Routes for addItem:
Serverless: POST /additem
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type

Serverless: Routes for emailOrderStatus:
Serverless: (none)

Serverless: Routes for sendEmail:
Serverless: (none)

Serverless: Routes for deleteItem:
Serverless: DELETE /item
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type

Serverless: Routes for saveOrderStatus:
Serverless: POST /save_order_status
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type

Serverless: Routes for getUser:
Serverless: POST /get_user
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type

Serverless: Routes for pastOrders:
Serverless: POST /past_orders
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type

Serverless: Routes for allItems:
Serverless: POST /all_records
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type

Serverless: Routes for restore:
Serverless: POST /restore
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type

Serverless: Routes for itemQuery:
Serverless: POST /query

Serverless: Routes for itemLoad:
Serverless: POST /item_data
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type

Serverless: Routes for itemSave:
Serverless: POST /item
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type

Serverless: Routes for cartGuest:
Serverless: POST /cart_guest

Serverless: Routes for cartAuth:
Serverless: POST /cart_auth
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type

Serverless: Routes for buyGuest:
Serverless: POST /buy_guest

Serverless: Routes for buyAuth:
Serverless: POST /buy_auth
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type

Serverless: Routes for react:
Serverless: ANY /
Serverless: ANY /{proxy*}

Serverless: Offline listening on http://0.0.0.0:3000

Serverless: ANY / (ฮป: react)
sessionID: SIJ0soLd7YGQdew5I3h5BHnzlyOVIccd
Debug: internal, implementation, error
TypeError: Uncaught error: Cannot read property 'done' of undefined
at createLambdaContext (/home/max/Documents/code/ark/trinity/nextjs/node_modules/serverless-offline/src/index.js:671:44)
at process.nextTick (/home/max/Documents/code/ark/trinity/nextjs/node_modules/serverless-http/lib/dispatch.js:7:9)
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickDomainCallback (internal/process/next_tick.js:219:9)


Most helpful comment

This is not fixed for me in 4.10.3:

(node:2229) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'done' of undefined
    at createLambdaContext (/home/circleci/project/node_modules/serverless-offline/src/index.js:671:44)
    at handler.catch.then.then.response (/home/circleci/project/functions/dist/service/src/handlers/webpack:/packages/service/src/lib/apiGatewayHandler.ts:133:1)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)

All 9 comments

Hi @mkondel
That's weird I cannot reproduce...
Is that a one time error or are you getting it all the time ?

@mkondel could you create a small repro I could look into? I'm pretty sure it's the memory leak fix which went into the last release.

I'm getting the same error when running a python lambda, nodejs lambda seems to be working fine though.
To reproduce just create a new aws-python serverless lambda and try running it with an http event.

Hi @dherault and @dnalborczyk. Here is a stripped down version of my project: https://github.com/mkondel/serverless-offline-test. The steps to reproduce are in the readme. You do not need to deploy to AWS, the error and fix will show on localhost alone.

I'm getting this, too. What I'm seeing is that there is a call to setTimeout on line 973 that clears the details of the current request. The problem is that the setTimeout function is getting called _before_ the handler itself, which I'm guessing wasn't intended. If I put a few breakpoints in the serverless-offline index file (but don't alter anything), I can actually get the setTimeout function to fire after the handler function fires.

If I had to speculate, I would guess that the setTimeout is used to schedule the deletion of the requests object after the handler has run, but when the handler is async and yields execution to some async function (DynamoDB, file IO, etc.), the scheduled setTimeout function is next on the list of things to execute, so it does.

If it helps, I'm using node 10.15 and my handler is async.

If I comment out the lines about DynamoDBStore, then the error only happens on the command line, but the browser renders the page. https://github.com/mkondel/serverless-offline-test/blob/master/lambdas/server.js#L14

This is not fixed for me in 4.10.3:

(node:2229) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'done' of undefined
    at createLambdaContext (/home/circleci/project/node_modules/serverless-offline/src/index.js:671:44)
    at handler.catch.then.then.response (/home/circleci/project/functions/dist/service/src/handlers/webpack:/packages/service/src/lib/apiGatewayHandler.ts:133:1)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)

@aaronjensen try the workaround from https://github.com/dherault/serverless-offline/issues/661#issuecomment-493202885, it fixed the problem for my app.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidroman0O picture davidroman0O  ยท  4Comments

yareyaredesuyo picture yareyaredesuyo  ยท  4Comments

Ali-Dalal picture Ali-Dalal  ยท  4Comments

adambiggs picture adambiggs  ยท  4Comments

ktwbc picture ktwbc  ยท  4Comments