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

Claudia package validation fails with Lambda Layers #194

Closed jlarmstrongiv closed 5 years ago

jlarmstrongiv commented 5 years ago

I understand why claudia is throwing errors. I do not actually have that module installed. It is actually installed inside the Lambda Layer, which the package validator has no knowledge of.

It would be great to either pass an array of packages included in lambda layer to ignore validation errors for those packages. Or, as a quickfix, just skip the validator when using Layers. There’s probably other solutions I am unaware of.

Adding sharp as a dev or optional dependency did not work.

gojko commented 5 years ago

A workaround is to lazy-load sharp - don't require it in the main instantiation chain for the entry-level class. So require and load it inside a function that actually uses it.

Claudia needs to instantiate the API class to read the configuration, so the current design makes it impossible to skip validation.

jlarmstrongiv commented 5 years ago

This package solved my problems https://github.com/sindresorhus/import-lazy#usage-with-bundlers though this stage-4 dynamic import feature will be more future-proof (example 1, 2). Use optional dependencies for development mode.

nick-tw commented 4 years ago

thanks. lazy load works for sharp.