node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

Add ESM support

Open LJNeon opened this issue 5 years ago • 6 comments
trafficstars

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 avatar Sep 26 '20 01:09 LJNeon

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

LJNeon avatar Sep 27 '20 08:09 LJNeon

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

Please do. Or fork the project.

btakita avatar Jan 02 '22 23:01 btakita

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

brianc avatar Jan 05 '22 04:01 brianc

What is the status of this one?

orangecoding avatar May 05 '22 12:05 orangecoding

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

LJNeon avatar May 05 '22 16:05 LJNeon

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

btakita avatar May 05 '22 22:05 btakita

+1

real2two avatar Nov 25 '22 22:11 real2two