brianc / node-postgres

PostgreSQL client for node.js.
https://node-postgres.com
MIT License
12.21k stars 1.22k forks source link

Errors with Vite+Vue / Nuxt+Vue #3253

Closed VassilisM closed 3 months ago

VassilisM commented 3 months ago

Hi. I am importing pg and creating a pool.

After I added define: { "process.env": {}, }, to vite.config.ts file to counter a previous error, it still cannot continue:

image

For the Nuxt version of the same project I get:

image

Based on the troubleshooting link, ..."If the module is imported from a third-party library (that's meant to be used in the browser), it's advised to report the issue to the respective library." and that is why I am opening this issue. Now, I suppose that it may as well run in browser. I mean, what would possibly be the difference from node . running the original pure js project? (which I am migrating with UI)

https://stackoverflow.com/questions/76188415/vue3-vite-module-has-been-externalized And would this be a solution for it? function getCrypto() { try { return window.crypto; } catch { return crypto; } }

GabenGar commented 3 months ago

What is the issue though? Looks like pg got dragged into browser bundle, so it's more of a vite/vue/nuxt problem.

VassilisM commented 3 months ago

Yes, that is what I mean. It has to be browser. Is that possible or not? And if not, why not? There shouldn't be much difference from just running that with node, or is there?

charmander commented 3 months ago

If the module is imported from a third-party library (that's meant to be used in the browser)

pg is not meant to be used in the browser. You can’t make plain TCP connections from a browser, among several other problems. (At the risk of being confusing, I’ll mention that it’s not impossible to do useful work with the PostgreSQL protocol in browser JavaScript, but if you really wanted that you would have said so. And pg doesn’t support that in any case.)

VassilisM commented 3 months ago

So, not possible, cool, bummer but cool. Thank you :-)