unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.5k stars 472 forks source link

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

Closed leo91000 closed 1 month ago

leo91000 commented 2 years ago

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

WebDeveloperBen commented 3 months ago

any movement on this issue?

pi0 commented 1 month ago

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)

WebDeveloperBen commented 1 month ago

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", },

pi0 commented 1 month ago

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

WebDeveloperBen commented 1 month ago

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