-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
support esm #3060
Comments
fwiw there is very, very little (if any) code that would be removed with tree-shaking if you are importing the pool. It literally depends on all the code in the project. |
is the documentation wrong? @brianc https://node-postgres.com/
|
I'm open to a pull request to add ESM support so long as it maintains backwards compatibility. |
I will take a look @brianc maybe in this weekend |
Hello, and thank you for the library @brainc <3 I got to this issue because the docs imply this type of import is supported here: https://node-postgres.com/apis/pool import { Pool } from 'pg'
const pool = new Pool({
host: 'localhost',
user: 'database-user',
max: 20,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000,
}) Should the docs be updated to the following? import pg from 'pg'
const pool = new pg.Pool({
host: 'localhost',
user: 'database-user',
max: 20,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000,
}) |
nice <3 |
Why is the documentation written in a way that clearly doesn’t work? |
Update pg import for CommonJS pg package does not support ESM so the imports need to handle CommonJS See: <brianc/node-postgres#3060>
FFS 07.2024 and the docs are stil not changed. |
are the docs inaccurate? If so it would be helpful if you would point out where. I went through a while ago and tried to make them all clear and correct. You could also do a PR with the changes if that's easier. |
@brianc you might not have experienced issues if your projects build to commonJS, or you do build to ESM but you bundle the entire pg library. IF you try to run the project in ESM without a bundler converting your source code, this runtime error will happen. It's verifiable here as well: The docs are inaccurate in that when running in an ESM environment, named imports of Pg won't work.
the solution is that you define an I could open a PR to do so if you agree with this solution. What do you think? |
if all it is is a package.json thing? abso-luuutely open to that! Last time I looked at building both esm and commonjs from the same codebase (granted this was like a year ago) my face melted at the complexity! |
I'm just a bystander here, but I have had a good experience with the https://arethetypeswrong.github.io/ tool. Things are made a lot simpler by it - basically if it says everything is ok (checkable with My codebase at work is also affected by this, so maybe I can offer additional testing. |
@mikavilpas can you test my PR? |
Hmm I looked into this, but I'm not sure if this is the same error at all. import { Pool } from 'pg'
^
SyntaxError: The requested module 'pg' does not provide an export named 'Pool'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:180:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:263:5)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:547:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5)
Node.js v22.13.1 Maybe I have a different error. Hopefully someone else can help test it. |
when running this package inside an ESM project, I got this error
using the suggested form
import pkg from 'pg';
disables the tree-shakingThe text was updated successfully, but these errors were encountered: