title: How to make ES modules import from a Lambda layer work?
body: <p>I have a lambda function in node v14 that imports AWS SDK v3 from a lambda layer.</p>
  <p>In my function I can use my node modules from the layer only if I use CommonJS syntax:</p>
  <pre><code>const { parseUrl } = require('@aws-sdk/url-parser');
  </code></pre>
  <p>Using ES modules doesn't work.</p>
  <pre><code>import { parseUrl } from '@aws-sdk/url-parser';
  </code></pre>
  <p>It will throw an error:
  <code>&quot;errorMessage&quot;: &quot;Cannot find package '@aws-sdk/url-parser' imported from /var/task/index.js\nDid you mean to import @aws-sdk/url-parser/dist-cjs/index.js?&quot;</code></p>
  <p>It should work. I have <code>&quot;type&quot;: &quot;module&quot;</code> in <code>package.json</code> and locally the import works.
  It also starts working when I specify the full path to cjs index file:</p>
  <pre><code>import { parseUrl } from '/opt/nodejs/node_modules/@aws-sdk/url-parser/dist-cjs/index.js';
  </code></pre>
  <p>Which is really weird.</p>
  <p>I checked <code>NODE_PATH</code> and <code>/opt/nodejs/node_modules</code> is there so I don't know where the problem is.</p>
  <p>The full implementation is here so you can replicate the error:
  <a href="https://github.com/simon-q/lambda-layer-es-modules-error" rel="noreferrer">https://github.com/simon-q/lambda-layer-es-modules-error</a></p>
  <p>Is it something broken in lambda layers or am I doing something wrong?
  I would really appreciate any help.</p>
  <p>Thanks.</p>