DEV Community

Vikas Kumar
Vikas Kumar

Posted on • Originally published at geekyhub.in on

Stop using serverless-webpack for AWS Lambda

I see that nodejs lambda projects are built using serverless and often include serverless-webpack. It is used to implement babel and get the latest javascript syntaxes, especially module and top-level awaits.

But as per this blog post, the AWS lambda environment already supports these features, so we should no longer need to use serverless-webpack.

There are some cons that I face while using webpack in serverless.

  1. Code is transpiled (and optionally minified), making it challenging to debug from logs, as line numbers and function names may not be the same per your development environment.
  2. Using ESM only module is not straightforward. Such as node-fetch and d3, and the ESM-only module list is growing daily.
  3. There could also be a performance impact as the code will be converted to commonJS, and this benchmark test shows that commonsJS could perform 43% worse than ESM.

There are other benefits of babel and webpack besides transpiling to commonJS. But these are mostly catered towards browsers and not serverside usage.

How to use ESM in serverless? Just add "type": "module" in pacakge.json in it will work in node 14.x and node 16.x.

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →