Skip to content

ES module support #44

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

Closed
majg0 opened this issue Jan 20, 2022 · 5 comments
Closed

ES module support #44

majg0 opened this issue Jan 20, 2022 · 5 comments

Comments

@majg0
Copy link

majg0 commented Jan 20, 2022

https://aws.amazon.com/about-aws/whats-new/2022/01/aws-lambda-es-modules-top-level-await-node-js-14/

Also; is this maintained? Last commit Nov 3 2021, open issues and outstanding PRs.

@darrinholst
Copy link

So cracking open the latest amazon/aws-lambda-nodejs image I see this in UserFunction.js...

  // If still not loaded, try .js, .mjs, and .cjs in that order.
  // Files ending with .js are loaded as ES modules when the nearest parent package.json
  // file contains a top-level field "type" with a value of "module".
  // https://nodejs.org/api/packages.html#packages_type
  const loaded =
    (pjHasModule && _tryAwaitImport(lambdaStylePath, ".js")) ||
    _tryAwaitImport(lambdaStylePath, ".mjs") ||
    _tryRequireFile(lambdaStylePath, ".cjs");

so it looks to have been added, but hasn't made it up to this repo yet?

@tforster
Copy link

It's now more than halfway through June. Is there any update on this issue? It's pretty critical not to be able to use ES modules in 2022.

@daniel-gato
Copy link

Same here, we need this asap.

miki725 added a commit to crashappsec/aws-lambda-nodejs-runtime-interface-client that referenced this issue Apr 7, 2023
Within ES modules (type is module inside package.json), if you try
to either:

```
require('file')
require('file.js')
```

it does not allow that as imports should be used within ES modules.
The only way to use require() is to explicitly require `.cjs` file
which explicitly insidicates that path is a CommonJS file, not ESM:

```
require('file.cjs')
```

This change allows to require .cjs files when a user function is being
searched. I would imagine eventually this library would need to fully
support ES modules as per
aws#44
however this diff will allow people to use lambdas within ES modules
if they have .cjs lambda files.
@govindrai
Copy link

Don't want to repeat the same request but it would be great it to get some response from maintainers

@krk
Copy link

krk commented Jun 23, 2023

This is fixed in #70.

@krk krk closed this as completed Jun 23, 2023
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

6 participants