Skip to content

Add ESM support #2353

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

Open
LJNeon opened this issue Sep 26, 2020 · 7 comments
Open

Add ESM support #2353

LJNeon opened this issue Sep 26, 2020 · 7 comments

Comments

@LJNeon
Copy link

LJNeon commented Sep 26, 2020

When importing a CommonJS library, it's flattened into a single object, and you're unable to take advantage of any ESM features. However if you add a few lines to your package.json and a esm.mjs wrapper file that simply re-exports the contents of index.js, then ESM users will be able to take full advantage of ESM features without any changes needed to your source code, and without affecting any CommonJS users. The package.json changes would be as simple as:

"main": "index.js",
"exports": {
  ".": [
    {"require": "index.js", "import": "esm.mjs"},
    "index.js"
  ],
  "./": "./"
}

The "index.js" fallback is only necessary to avoid package.json parsing errors in some older versions of Node, which would affect CommonJS users as well. If this library ever supports only Node 14+ in the future, the fallback could be removed.

@LJNeon
Copy link
Author

LJNeon commented Sep 27, 2020

I would be happy to open a pull request but wish to confirm interest from the maintainers first.

@btakita
Copy link

btakita commented Jan 2, 2022

I would be happy to open a pull request but wish to confirm interest from the maintainers first.

Please do. Or fork the project.

@brianc
Copy link
Owner

brianc commented Jan 5, 2022

yea submit a pr I'd love to take a look at it

@orangecoding
Copy link

What is the status of this one?

@LJNeon
Copy link
Author

LJNeon commented May 5, 2022

I'm currently not able to sit down and do this, but if someone else wanted to that would be great.

@btakita
Copy link

btakita commented May 5, 2022

I switched over to https://github.com/panates/postgresql-client for ESM & TS support. So far no problems.

@real2two
Copy link

+1

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

5 participants