nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Bundling of dependency `pg` fails for `workers` preset because it bundle the optional dependency `pg-native`. Is there a way to ignore this ?

Open leo91000 opened this issue 3 years ago • 1 comments

Environment

Node.JS : 16.15.0 NItro : 0.3.8

Reproduction

Here is a simple reproduction link : Stackblitz

Just run NITRO_PRESET=cloudflare npm run blitz

Notice the message 'pg-native' is imported by pg-native?commonjs-external, but could not be resolved – treating it as an external dependence

The .output/server/index.mjs build has now an import e as * from 'pg-native' : it is not compatible with cloudflare or any worker.

Describe the bug

To generate the build, nitro bundle pg with it's optional peer dependency pg-native. However, pg-native is not compatible with workers since it relies on libpq.

However this dependency is optional and it would work perfectly fine without it.

-> Is there a way to ignore this dependency, or to mock it because we never use it ?

Additional context

No response

Logs

No response

leo91000 avatar May 02 '22 20:05 leo91000

any movement on this issue?

WebDeveloperBen avatar Mar 19 '24 07:03 WebDeveloperBen

Hi. I assume latest version of pg should be more compatible with cloudflare workers. If you still experience issues, please ping to reopen 🙏🏼

(BTW main support will be done via db0 connectors)

pi0 avatar May 16 '24 17:05 pi0

Hi pi0, definitly better support with pg* and cloudflare for sure.

I was able to set these values in my nuxt project, for anyone that finds and is seeking a resolution

nitro: { esbuild: { options: { target: "ESNEXT", }, }, rollupConfig: { external: ["cloudflare:sockets"], }, preset: "cloudflare-pages", },

WebDeveloperBen avatar May 17 '24 07:05 WebDeveloperBen

TIL about cloudflare:sockets. Is there any link to docs for it? (we might add it to externals by default)

pi0 avatar May 17 '24 07:05 pi0

Nothing concrete, no. Seen it across various issues though. Most relevant would be this one: https://github.com/unjs/nitro/issues/1967

WebDeveloperBen avatar May 17 '24 10:05 WebDeveloperBen