Skip to content

Conversation

@rjgtav
Copy link
Contributor

@rjgtav rjgtav commented Oct 14, 2025

What?

Forces pg-cloudflare dependency to be installed, even when using pnpm install

Why?

When using the db-postgres adapter inside Cloudflare, it needs the pg-cloudflare package to work, which is an optional dependency of pg. This is necessary to support connecting to a Postgres database, via Cloudflare's Hyperdrive, when deploying Payload on Cloudflare.

Optional dependencies are installed by default when using npm, but not when using pnpm.

How?

By declaring pg-cloudflare as a dependency of db-postgres.
To help with the bundling, it's also necessary to add pg-cloudflare to the list of Next.js' external dependencies. More info here: https://opennext.js.org/cloudflare/howtos/workerd#configuration

Discord discussion: https://discordapp.com/channels/967097582721572934/1427199951766552586

return webpackConfig
},

serverExternalPackages: ['pg-cloudflare'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add this to the D1 template, which is currently being used as a base to implement Payload using Postgres with Hypedrive, or should this just go into the documentation, in a dedicated section?

DanRibbens pushed a commit that referenced this pull request Jan 7, 2026
…15094)

### What?
Adds recommended serverExternalPackages to the Cloudflare template

### Why?
To make packages with cloudflare-specific code work with OpenNext.
More details here: https://opennext.js.org/cloudflare/howtos/workerd

### How?
By adding the serverExternalPackages property to next.config.ts

May fix #14656
Also helps when connecting to Postgres instead of D1 as mentioned in
#14181

Co-authored-by: Ricardo Tavares <rtavares@cloudflare.com>
teastudiopl pushed a commit to teastudiopl/payload that referenced this pull request Jan 8, 2026
…ayloadcms#15094)

### What?
Adds recommended serverExternalPackages to the Cloudflare template

### Why?
To make packages with cloudflare-specific code work with OpenNext.
More details here: https://opennext.js.org/cloudflare/howtos/workerd

### How?
By adding the serverExternalPackages property to next.config.ts

May fix payloadcms#14656
Also helps when connecting to Postgres instead of D1 as mentioned in
payloadcms#14181

Co-authored-by: Ricardo Tavares <rtavares@cloudflare.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant