Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --nosources option for source maps #624

Closed
atombrenner opened this issue Dec 28, 2020 · 3 comments
Closed

Add --nosources option for source maps #624

atombrenner opened this issue Dec 28, 2020 · 3 comments

Comments

@atombrenner
Copy link

Context

I am using esbuild to bundle and minify Typescript functions for AWS lambda.

esbuild --bundle --minify --keep-names --sourcemap --platform=node --target=node12

To get meaningful stack traces for exceptions in production, I use the --sourcemap and --keep-names options.
I use NODE_OPTIONS=--enable-source-maps to get a stack trace that uses the source map.
One problem is, that I have to use the --keep-names option to see the original function names in the stack trace.
I guess that it could be related to the missing names field in the generated source map, but I'm not an expert on this topic.

Issue

The --sourcemap option adds the original source to the sourcesContentfield of the source map. This is not necessary for meaningful stack traces, it can be an empty array "sourcesContent": [].

Adding the complete source to the source map thwarts the goal of making the AWS Lamda artifact small
as it doubles the size of the zip package (index.js + index.js.map) I need to upload to AWS Lambda.

I would like an esbuild option --nosources that prevent sources from being included in the source map.
Something similiar to the webpack devtool option nosources-source-map

My current workaround is to post process the generated source map from esbuild and remove the sourcesContent.

@evanw
Copy link
Owner

evanw commented Dec 29, 2020

Thanks for the detail. Doing this makes sense. Injecting the original source code is by far the heaviest part of the source map, and is only useful in some scenarios.

I think nosources is not the right name because source maps have both a sources field and a sourcesContent field and the intent of the flag is to keep sources but discard sourcesContent. So I'll use a different name instead.

evanw added a commit that referenced this issue Dec 29, 2020
@evanw
Copy link
Owner

evanw commented Dec 29, 2020

This will be fixed in the next release. Closing.

@evanw evanw closed this as completed Dec 29, 2020
@p0wl
Copy link

p0wl commented Feb 4, 2021

wow, awesome, I just ran into exactly this (aws lambda with esbuild via aws-lambda-nodejs), and so happy to found that you added an option for it. Thanks for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants