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.57k stars 480 forks source link

Cloudflare pages deployment issue #1679

Open AsyncFox opened 10 months ago

AsyncFox commented 10 months ago

Environment

Nuxt 3.7 Nitro 2.6.2 Cloudflare Wrangler 3.6.0

Reproduction

StackBlitz: https://stackblitz.com/github/AsyncFox/nuxt-trpc-drizzle-repro Github repo: https://github.com/AsyncFox/nuxt-trpc-drizzle-repro

Describe the bug

After nuxi build , I tried wrangler pages dev dist/ to run locally, but it shows an error. I also tried deploy to cloudflare pages but it also failed. Using nuxi dev works fine.

Additional context

I am using trpc-nuxt and drizzle-orm. If you remove other procedures and only reserve hello procedure in server\trpc\routers\index.ts, it works fine. I guess it is also drizzle-orm related because hello procedure does not require any db operation.

Logs

Starting local server...
[mf:wrn] The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2023-08-14", but you've requested "2023-08-30". Falling back to "2023-08-14"...
service core:user:worker: Uncaught TypeError: P.exit is not a function
  at 1pqueguojs8.js:6475:119
X [ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.

And on cloudflare pages:

Error: Failed to publish your Function. Got error: Uncaught TypeError: P.exit is not a function
  at functionsWorker-0.297748013825073.js:6386:119
Hebilicious commented 10 months ago

Hi @AsyncFox, this might be related to the fact that cloudflare doesn't support the postgres package, could you try with pg ? https://developers.cloudflare.com/workers/databases/connect-to-postgres/#requirements This is because workerd doesn't support TCP and needs a compatible driver to connect to postgres instances.

AsyncFox commented 10 months ago

Hi @Hebilicious , I tried pg but when using nuxi build it generates a new error. I found a discussion post related to this but it was not helpful to this situation. But anyway, thanks for your reach out, I have temporarily moved to vercel for deployment.

Logs

[nitro 22:47:00]  ERROR  Error: Cannot resolve "pg-native" from "\\node_modules\\.pnpm\\pg@8.11.3\\node_modules\\pg\\lib\\native\\client.js" and externals are not allowed!
Hebilicious commented 10 months ago

Hi @Hebilicious , I tried pg but when using nuxi build it generates a new error. I found a discussion post related to this but it was not helpful to this situation. But anyway, thanks for your reach out, I have temporarily moved to vercel for deployment.

Logs

[nitro 22:47:00]  ERROR  Error: Cannot resolve "pg-native" from "\\node_modules\\.pnpm\\pg@8.11.3\\node_modules\\pg\\lib\\native\\client.js" and externals are not allowed!

I tried building your project on stackblitz by swapping out postgres for pg and did not encounter a build error. Are you able to build with pg for vercel, but not for cloudflare-pages ?

AsyncFox commented 10 months ago

Are you able to build with pg for vercel, but not for cloudflare-pages ?

Yes, that's right. Building for vercel works fine, but not for cloudflare-pages