GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add esm exports by brianc · Pull Request #3423 · brianc/node-postgres

Conversation

@brianc

@brianc brianc commented Apr 21, 2025

Copy link
Copy Markdown
Owner

This builds off of #3407 and hopefully helps address the issue here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jahands, fratzinger, martinliptak, avindra, mahnunchik, and cluedtke reacted with hooray emoji avindra reacted with heart emoji
All reactions
  • 🎉 6 reactions
  • ❤️ 1 reaction
mesqueeb and others added 8 commits March 20, 2025 08:23
@mesqueeb
build: add esm exports
98bc876
@mesqueeb
fix: add defaults as per arethetypeswrong report
c2cbc2b
@mesqueeb
fix: add missing types
b4c1a4e
@mesqueeb
lint
8a58659
@brianc
Merge branch 'master' of github.com:mesqueeb/node-postgres into mesqu…
c484282
…eeb-master
@brianc
Fix broken tests
7393084
@brianc
Add (failing) test for esm compat
6949c7a
@brianc
Begin moving files to proper extension and adding tests
0cb8fd4
@brianc
brianc requested a review from hjr3 as a code owner April 21, 2025 18:24
@brianc

brianc commented Apr 21, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Owner Author

Still adding more tests, but wanted to open the PR to see how it runs in CI.

edit: yay - tests are passing. now I'll add some more.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brianc
Add tests for connection-string and fix cloudflare module type and es…
0a0e298
…m compat
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Apr 21, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Deploying node-postgres with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8162202
Status: ✅  Deploy successful!
Preview URL: https://2ed736ef.node-postgres.pages.dev
Branch Preview URL: https://bmc-add-esm-exports.node-postgres.pages.dev

View logs

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brianc
Add query-stream and cursor as esm exports
ffd5adc
@brianc

brianc commented Apr 21, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Owner Author

todo:

  • test if this gets fixed
  • update documentation to ESM imports & put note about also supporting commonJS
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brianc
brianc requested review from Copilot and removed request for hjr3 April 21, 2025 19:03
Copilot AI reviewed Apr 21, 2025
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds ECMAScript Module (ESM) export wrappers for several pg-related packages to improve compatibility with ESM environments. Key changes include:

  • Creation of ESM wrapper files for pg-protocol, pg-pool, pg-native, pg-cursor, and pg-connection-string.
  • Addition of test files to verify the ESM exports.
  • Update of pg-cursor to use the pg module for retrieving Result and utils.

Reviewed Changes

Copilot reviewed 21 out of 28 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/pg-protocol/esm/index.js Adds ESM exports for pg-protocol re-exporting from the dist build
packages/pg-pool/esm/index.mjs Provides an ESM wrapper for pg-pool with default export
packages/pg-native/esm/index.mjs Provides an ESM wrapper for pg-native with default export
packages/pg-esm-test/pg.test.js Introduces tests for exported Client, Pool, and default export from pg
packages/pg-esm-test/pg-query-stream.test.js Verifies the default export for pg-query-stream
packages/pg-esm-test/pg-pool.test.js Validates the Pool constructor export for pg-pool
packages/pg-esm-test/pg-native.test.js Validates the Client constructor export for pg-native
packages/pg-esm-test/pg-cursor.test.js Verifies the default export for pg-cursor
packages/pg-esm-test/pg-connection-string.test.js Confirms the parsing functions export from pg-connection-string
packages/pg-esm-test/pg-cloudflare.test.js Tests the CloudflareSocket export, though the test description mismatches
packages/pg-cursor/index.js Refactors pg-cursor to import Result and utils from the pg module
packages/pg-cursor/esm/index.mjs Provides an ESM wrapper for pg-cursor with default export
packages/pg-connection-string/esm/index.mjs Exposes the parse, toClientConfig, and parseIntoClientConfig functions via ESM
Files not reviewed (7)
  • package.json: Language not supported
  • packages/pg-cloudflare/package.json: Language not supported
  • packages/pg-connection-string/package.json: Language not supported
  • packages/pg-cursor/package.json: Language not supported
  • packages/pg-esm-test/package.json: Language not supported
  • packages/pg-native/package.json: Language not supported
  • packages/pg-pool/package.json: Language not supported
Comments suppressed due to low confidence (1)

packages/pg-esm-test/pg-cloudflare.test.js:5

  • The test description 'pg-pool' does not match the Cloudflare context; consider renaming it to 'pg-cloudflare' for clarity.
describe('pg-pool', () => {

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
brianc added 12 commits April 21, 2025 14:04
@brianc
Update PR copilot review
6a9b873
@brianc
Publish
56762be
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
@brianc
More cf compat work
69e5697
@brianc
Publish
306fa83
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
@brianc
Add more cf compat and update tests
9e7a1f7
@brianc
Make tests pass - update exports for esm
2969c15
@brianc
Use env vars for test connection in cf tests
0d6c737
@brianc
Fix lint
5a0f59c
@brianc
Fit vitest into existing legacy framework
42d00fa
@brianc
Skip worker tests on node below 18
cccda27
@brianc
Revert doc changes for now
d3a8b42
@brianc
Remove legacy worker test in favor of vitest
8162202
@brianc
brianc merged commit 940479b into master Apr 22, 2025
@brianc brianc mentioned this pull request Apr 22, 2025
build: add esm exports #3407
Closed
This was referenced Apr 23, 2025
[email protected] breaks node-pg-migrate: cannot access './lib/connection-parameters.js' due to package exports salsita/node-pg-migrate#1398
Closed
fix(exports): resolve issues with module imports and requires #3428
Merged
@B4nan

B4nan commented Apr 23, 2025

Copy link
Copy Markdown

This feels breaking, since now you are disallowing the imports for pg/lib/type-overrides. Or is there some other way to do this import?

import TypeOverrides from 'pg/lib/type-overrides';
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mesqueeb

mesqueeb commented Apr 23, 2025

Copy link
Copy Markdown
Contributor

@B4nan importing from undocumented paths is debatable wether it's breaking or not.

To my understanding, in an ESM environment this (your snippet) will get tricky since the source code is mostly CJS, and ESM only has single wrapper index files.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@B4nan

B4nan commented Apr 23, 2025

Copy link
Copy Markdown

Fair enough, but how can we do this properly if this was the wrong way? i believe that class is supposed to be used in downstream.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mesqueeb

mesqueeb commented Apr 23, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

@B4nan I guess the best way is to make sure that class is also exported as part of the esm-facing index file.
So that you can do:
import { TypeOverrides } from 'pg'
That should be a simple addition if this isn't already the case.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@B4nan

B4nan commented Apr 23, 2025

Copy link
Copy Markdown

Btw I learned about this trick ages ago from this issue, maybe there is another way to override type mapping per connection?

#1838

There is an old PR that was exposing the class in root exports but it never got merged.

#2369

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mesqueeb

mesqueeb commented Apr 23, 2025

Copy link
Copy Markdown
Contributor

@B4nan I did what i could by adding a voice: #2369 (comment)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@perrin4869 perrin4869 mentioned this pull request Apr 29, 2025
feat(pg): add default export DefinitelyTyped/DefinitelyTyped#72649
Merged
8 tasks done
@abrenneke abrenneke mentioned this pull request Dec 22, 2025
support esm #3060
Closed
WolfieLeader added a commit to WolfieLeader/node-postgres that referenced this pull request Oct 6, 2026
@WolfieLeader
fix(pg-protocol): ship the ESM entry as esm/index.mjs
2dc6dcc
pg-protocol is the only package from brianc#3423 whose ESM wrapper is a .js
file in a package without "type": "module". Node loads it as ESM only
through module syntax detection. Without detection (Node 18, or
--no-experimental-detect-module), `import { parse } from 'pg-protocol'`
fails with "Named export 'parse' not found".

Rename it to esm/index.mjs, like pg, pg-pool, pg-cursor and the other
packages.
@WolfieLeader WolfieLeader mentioned this pull request Oct 6, 2026
fix(pg-protocol): ship the ESM entry as esm/index.mjs #3807
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@brianc @B4nan @mesqueeb
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.