claudiajs / claudia

Deploy Node.js projects to AWS Lambda and API Gateway easily
https://claudiajs.com
MIT License
3.8k stars 274 forks source link

Lambda can't find NodeJS layer packages during compilation #198

Closed hiren-quovantis closed 5 years ago

hiren-quovantis commented 5 years ago

I am referring to one of the dependencies ('mssql' included in the layer) from my index js file.

  1. Simply create a nodejs layer as described here: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path and Deploy it
  2. Create a new lambda (index.js file) and refer to any of the packages installed in Nodejs layer.
  3. Try deploying the lambda using Claudia create or Claudia update command
gojko commented 5 years ago

if this fails during claudia packaging, there are two options:

1) install mysql as an optional dependency , then use --no-optional-dependencies when you deploy with claudia. it will not bundle the dependency in the package, but it will pass validation 2) lazy-load the required package (not in the file headers, but in a function on first use) to use layer dependencies that are not bundled with your code. alternatively, you can