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",
(09:11:57)[max@think nextjs]$ yarn; node-prune; yarn build; yarn devel yarn run v1.12.3 Using external babel configuration โ / Done in 52.04s. Serverless: Routes for imageWatermark: Serverless: Routes for getCounts: Serverless: Routes for getCartGuest: Serverless: Routes for getCartAuth: Serverless: Routes for checkUserDb: Serverless: Routes for imageCleanup: Serverless: Routes for addItem: Serverless: Routes for emailOrderStatus: Serverless: Routes for sendEmail: Serverless: Routes for deleteItem: Serverless: Routes for saveOrderStatus: Serverless: Routes for getUser: Serverless: Routes for pastOrders: Serverless: Routes for allItems: Serverless: Routes for restore: Serverless: Routes for itemQuery: Serverless: Routes for itemLoad: Serverless: Routes for itemSave: Serverless: Routes for cartGuest: Serverless: Routes for cartAuth: Serverless: Routes for buyGuest: Serverless: Routes for buyAuth: Serverless: Routes for react: Serverless: Offline listening on http://0.0.0.0:3000 Serverless: ANY / (ฮป: react)
Full logs from building to the error:
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
$ rm -rf .next && next build
Creating an optimized production build ...
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
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: (none)
Serverless: POST /counts
Serverless: POST /get_cart_guest
Serverless: POST /get_cart_auth
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type
Serverless: POST /checkUserDb
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type
Serverless: (none)
Serverless: POST /additem
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type
Serverless: (none)
Serverless: (none)
Serverless: DELETE /item
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type
Serverless: POST /save_order_status
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type
Serverless: POST /get_user
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type
Serverless: POST /past_orders
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type
Serverless: POST /all_records
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type
Serverless: POST /restore
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type
Serverless: POST /query
Serverless: POST /item_data
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type
Serverless: POST /item
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type
Serverless: POST /cart_guest
Serverless: POST /cart_auth
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type
Serverless: POST /buy_guest
Serverless: POST /buy_auth
Serverless: WARNING: Serverless Offline does not support the AWS_IAM authorization type
Serverless: ANY /
Serverless: ANY /{proxy*}
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)
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.
Most helpful comment
This is not fixed for me in 4.10.3: