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
6k stars 496 forks source link

Error with postgres@3.4.0 when building for cloudflare #1967

Open dev-cetus opened 10 months ago

dev-cetus commented 10 months ago

Environment

Reproduction

all code is here on powershell, run..

$env:NITRO_PRESET='cloudflare'
pnpm run build

Describe the bug

When I build the app to deploy it to cloudflare workers, I get an error about "cloudflare:sockets" in the postgres package. Cannot resolve "cloudflare:sockets" from "[...]\\node_modules\\.pnpm\\postgres@3.4.0\\node_modules\\postgres\\cf\\polyfills.js" and externals are not allowed!

Additional context

No response

Logs

No response

ElioStalteri commented 7 months ago

you can solve this by adding an additional piece in the config as follow

//https://nitro.unjs.io/config
export default defineNitroConfig({
  preset: "cloudflare-pages",
  rollupConfig: {
    external: ["cloudflare:sockets"],
  },
});
dev-cetus commented 6 months ago

thanks it works, no more problem with cloudflare:sockets! But now I have a problem with aws-sdk (although I don't deploy on aws)

Cannot resolve "aws-sdk" from "...\\node_modules\\.pnpm\\@mapbox+node-pre-gyp@1.0.11\\node_modules\\@mapbox\\node-pre-gyp\\lib\\util\\s3_setup.js" and externals are not allowed!

I did put this configuration in, as @ElioStalteri said:

  nitro: {
    preset: "cloudflare-pages",
    rollupConfig: {
      external: ["cloudflare:sockets"],
    },
  },