aws / aws-lambda-builders

Python library to compile, build & package AWS Lambda functions for several runtimes & framework
Apache License 2.0
329 stars 136 forks source link

Bug: deplyoyment issue with esbuild > 0.22.0 #662

Closed anthony-nhs closed 2 weeks ago

anthony-nhs commented 2 weeks ago

Description

esbuild 0.22.0 (https://github.com/evanw/esbuild/releases/tag/v0.22.0) changes the default behavior for packages so that dependencies are no longer bundled. You can overwrite this by specifying --packages=bundle. This should be the default for packages compiled with esbuild as specified it in Metadata properties of AWS::Serverless::Function and deployed through SAM so that dependencies are available in the deployed lambda

Steps to reproduce:

Install esbuild >0.22.0 Create a typescript lambda with a 3rd party dependency and deploy it using sam-cli using esbuild. Try executing the deployed lambda

Observed result:

Get error Error: Cannot find module....

Expected result:

lambda executes

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: linux
  2. If using SAM CLI, sam --version: 1.120.0
  3. AWS region: eu-west-2

Add --debug flag to any SAM CLI commands you are running

mildaniel commented 2 weeks ago

Thanks for reporting @anthony-nhs. We're aware of the issue and will prioritize a fix. In the meantime, if anyone is having this issue, as a workaround, you can either

  1. Revert the esbuild version you are using the < 0.22.0
  2. Add the --packages=bundle flag under the function metadata
mildaniel commented 2 weeks ago

This breaking change has now been reverted in the latest version of esbuild.

https://github.com/evanw/esbuild/releases/tag/v0.23.0

For the purposes of AWS SAM CLI, refrain from using esbuild version 0.22.0 and things should work as expected.