Bug: Wrong handler mapping after esbuild
See original GitHub issueDescription:
When running esbuild on a Lambda function, the output doesn’t mantain the same folder structure as the enry points, and this remains unchange in the built template, resulting in SAM not finding the lambda Handler:
Steps to reproduce:
Project structure:
- package.json
- template.yaml
-- src
--- functions
---- FunctionName
----- app.js
--- utils
---- some-util.js
Template.yaml:
FunctionName:
Type: AWS::Serverless::Function
Metadata:
BuildMethod: esbuild
Properties:
Handler: src/functions/FunctionName/app.Handler
Events:
HttpEvent:
....
Observed result:
code is budled to FunctionName folder in .aws-build resulting in:
- .aws-build
-- build
--- template.yaml
--- FunctionName
---- app.js
However, the built template results in:
FunctionName:
Type: AWS::Serverless::Function
Metadata:
BuildMethod: esbuild
Properties:
CodeUri: FunctionName
Handler: src/functions/FunctionName/app.Handler
Events:
HttpEvent:
....
Resulting in an error since FunctionName/src/functions/FunctionName/app.Handler
Expected result:
Handler in built template should match esbuild output. I.E:
FunctionName:
Type: AWS::Serverless::Function
Metadata:
BuildMethod: esbuild
Properties:
CodeUri: FunctionName
Handler: app.Handler
Events:
HttpEvent:
....
Issue Analytics
- State:
- Created a year ago
- Comments:15 (7 by maintainers)
Top Results From Across the Web
API - esbuild
This API call is used by the command-line interface if no input files are provided and the --bundle flag is not present. In...
Read more >Building Node.js Lambda functions with esbuild
Specifies whether the bundler produces a source map file. The default value is false . When set to true , NODE_OPTIONS: --enable-source-maps is...
Read more >Comparing the New Generation of Build Tools - CSS-Tricks
Then, I used the following command to compile the app into a dist/bundle.js file: ./node_modules/.bin/esbuild src/app.jsx --bundle ...
Read more >Using esbuild in Your Serverless Framework Project
How to use the extremely fast esbuild to bundle TypeScript-based AWS Lambda function handlers with the Serverless Framework — all without ...
Read more >TypeScript and jsbundling and Rails 7 - Noel Rappin
js.map" , meaning removing the existing esbuild files from the build directory so that the development browser page will error rather than ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve found a similar problem when using regular
sam init
(v 1.57):Quick Start, Hello World, nodejs16.x, Zip, Typescript.
First thing to note is that if I invoke
sam build
and thensam local start-api -d 3099
and then attach my debugger as I invoke a curl command, I am able to set breakpoints inhello-world/app.ts
and step through with my debugger.If I then add two subfolders:
Then I’m faced with a conundrum:
If, for each
AWS::Serverless::Function
, I pointCodeUri
to a subfolder like/hello-world/hello1
, it complains about not finding a package.json. It sayspackage.json file not found. Bundling source without dependencies.
The resultantapp.js.map
in.aws-sam
does have an accuratesources
entry though, e.g."sources": ["../../../hello-world/hello1/app.ts"],
If I instead revert
CodeUri
to point to the folder with package.json, then I need to indicate the path to the new function a different way. If I chooseHandler
, e.g.Handler: hello1/app.lambdaHandler
, (assuming Handler evaluates from theCodeUri
directory), then it appears to build correctly but.aws-sam/build/HelloOneFunction
includes the wrong source, meaning the source forHelloWorldFunction
instead. Additionally, theapp.js.map
file refers to a file inprivate/var/folders
that does not exist:(everything up through the
/T
exists, but thetmp...
folder does not.)EntryPoints
, e.g.hello2/app.ts
, then.aws-sam/build/HelloTwoFunction/app.js
includes the correct source, but itsapp.js.map
again points to a file inprivate/var/folders
that does not exist.If I leave those folders in place in the filesystem, but remove them from template.yaml, then I can still set breakpoints on the original
hello-world/app.ts
function. However, if I addAWS::Serverless::Function
definitions for either of the two new subfolder functions into template.yaml, then the breakpoints don’t work anymore - not even on the originalhello-world/app.ts
function.I believe that for codebases with multiple functions, it would be preferable to share one package.json that is from a common parent folder, and to also be able to use a debugger on these functions.
@mildaniel any news on this?