Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Allow Functions to be pure ES modules #750

Open
ehmicky opened this issue Oct 15, 2021 · 2 comments
Open

Allow Functions to be pure ES modules #750

ehmicky opened this issue Oct 15, 2021 · 2 comments
Labels
type: chore work needed to keep the product and development running smoothly

Comments

@ehmicky
Copy link
Contributor

ehmicky commented Oct 15, 2021

Parent issue: https://github.com/netlify/pod-workflow/issues/321

Users can currently use import/export statements in their Functions when using the esbuild bundler, which transpiles those to CommonJS before we ship it to AWS Lambda.

However, Functions can still not be pure ES modules (see this list for the differences). We should support it.

Some specific points we would check:

  • Supporting new package.json fields related to pure ES modules (like exports and imports)
  • Using import.meta.resolve() instead of require.resolve()
  • Not using __dirname nor __filename
  • Not importing JSON files directly

Also, we would need to confirm that AWS Lambda can run pure ES modules.

Related (but separate) issue to refactor this repository to use pure ES modules: #749

@ehmicky ehmicky added the type: chore work needed to keep the product and development running smoothly label Oct 15, 2021
@jimmywarting
Copy link

I can't certainly say what needs to be done/fix or if pure ESM works or not, i don't use netlify or aws lambda.

But from my understanding AWS Lambda can run pure ES modules. but they need to be imported using lazy import import('main.js')

Behind the scenes AWS uses require to load the file/module so your own entry point need to do: import(./main.js) but this is something i think AWS should fix, maybe you can vote/send PR to AWS to fix it?

@thescientist13
Copy link

This would be awesome! 🤓

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: chore work needed to keep the product and development running smoothly
Projects
None yet
Development

No branches or pull requests

3 participants