<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>NodeJS on GeekyHub</title>
    <link>https://www.geekyhub.in/tags/nodejs/</link>
    <description>Recent content in NodeJS on GeekyHub</description>
    <generator>Hugo -- 0.148.1</generator>
    <language>en</language>
    <lastBuildDate>Sun, 16 Oct 2022 15:50:08 +0530</lastBuildDate>
    <atom:link href="https://www.geekyhub.in/tags/nodejs/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Stop using serverless-webpack for AWS Lambda</title>
      <link>https://www.geekyhub.in/post/using-esmodule-in-serverless-aws-lambda/</link>
      <pubDate>Thu, 06 Oct 2022 15:38:00 +0530</pubDate>
      <guid>https://www.geekyhub.in/post/using-esmodule-in-serverless-aws-lambda/</guid>
      <description>AWS Lambda natively supports ES Module and top level await since node 14.x</description>
      <content:encoded><![CDATA[<p>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.</p>
<p>But as per this <a href="https://aws.amazon.com/about-aws/whats-new/2022/01/aws-lambda-es-modules-top-level-await-node-js-14/">blog post</a>, the AWS lambda environment already supports these features, so we should no longer need to use serverless-webpack.</p>
<p>There are some cons that I face while using webpack in serverless.</p>
<ol>
<li>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.</li>
<li>Using ESM only module is not straightforward. Such as node-fetch and d3, and the ESM-only module list is growing daily.</li>
<li>There could also be a performance impact as the code will be converted to commonJS, and this <a href="https://aws.amazon.com/blogs/compute/using-node-js-es-modules-and-top-level-await-in-aws-lambda/">benchmark test</a> shows that commonsJS could perform 43% worse than ESM.</li>
</ol>
<p>There are other benefits of babel and webpack besides transpiling to commonJS. But these are mostly catered towards browsers and not serverside usage.</p>
<p>How to use ESM in serverless? Just add <code>&quot;type&quot;: &quot;module&quot;</code> in <code>pacakge.json</code> in it will work in node 14.x and node 16.x.</p>
]]></content:encoded>
    </item>
  </channel>
</rss>
