serverless-express: unable to import module "lambda"

I’m trying to migrate an existing express app.

I’ve deployed, but I’m getting this error in Cloudwatch:

Unable to import module 'lambda': Error
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)

And “internal server error” when trying to hit my ApiUrl.

I’m requireing my server in lambda.js and changed "main": in my package.json to lambda.js as well as following the other instructions. Could I be missing something obvious?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 8
  • Comments: 19 (1 by maintainers)

Most upvoted comments

This is a generic error that is not specific to this project.

It seems that this is a generic error which hides the real issue. The most consistent way I’ve found to debug is via the API Gateway test console which actually reveals the root error messages.

I did download the created package and could not run it locally. When running it locally proper error got displayed that hinted at the problem. The problems were the missing dependencies (for some reasons npm install did only install top level dependencies, but not others). After moving the examples directory to its own directory, it worked.

in case you are using serverless framework to deploy , ensure you do npm install of all your packages before deploying the lamda function.

I think this stems from how the function is being zipped up. I’ve seen in the past where the whole folder will get zipped instead of the contents of the folder-- lambda freaks out a little about that.

I would suggest making sure that you’re zipping up the contents of the folder and re-upload that file.