Skip to content

Replace cloudflare export condition in pg-cloudflare with workerd #3498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/pg-bundler-test/esbuild-cloudflare.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ await esbuild.build({
entryPoints: ['./src/index.mjs'],
bundle: true,
outfile: './dist/esbuild-cloudflare.js',
conditions: ['import', 'cloudflare'],
conditions: ['import', 'workerd'],
})
2 changes: 1 addition & 1 deletion packages/pg-bundler-test/rollup-cloudflare.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export default defineConfig({
file: 'dist/rollup-cloudflare.js',
format: 'es',
},
plugins: [nodeResolve({ exportConditions: ['import', 'cloudflare'], preferBuiltins: true }), commonjs()],
plugins: [nodeResolve({ exportConditions: ['import', 'workerd'], preferBuiltins: true }), commonjs()],
external: ['cloudflare:sockets'],
})
2 changes: 1 addition & 1 deletion packages/pg-bundler-test/vite-cloudflare.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default defineConfig({
},
},
resolve: {
conditions: ['import', 'cloudflare'],
conditions: ['import', 'workerd'],
},
plugins: [commonjs()],
})
2 changes: 1 addition & 1 deletion packages/pg-bundler-test/webpack-cloudflare.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
output: {
filename: 'webpack-cloudflare.js',
},
resolve: { conditionNames: ['import', 'cloudflare'] },
resolve: { conditionNames: ['import', 'workerd'] },
plugins: [
// ignore cloudflare:sockets imports
new webpack.IgnorePlugin({
Expand Down
13 changes: 9 additions & 4 deletions packages/pg-cloudflare/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ config. For example:
```js
export default {
...,
resolve: { conditionNames: [..., "cloudflare"] },
resolve: { conditionNames: [..., "workerd"] },
plugins: [
// ignore cloudflare:sockets imports
new webpack.IgnorePlugin({
Expand All @@ -29,11 +29,15 @@ config. For example:
}
```
- `vite.config.js`

> [!NOTE]
> If you are using the [Cloudflare Vite plugin](https://www.npmjs.com/package/@cloudflare/vite-plugin) then the following configuration is not necessary.

```js
export default defineConfig({
...,
resolve: {
conditions: [..., "cloudflare"],
conditions: [..., "workerd"],
},
build: {
...,
Expand All @@ -44,11 +48,12 @@ config. For example:
},
})
```

- `rollup.config.js`
```js
export default defineConfig({
...,
plugins: [..., nodeResolve({ exportConditions: [..., 'cloudflare'] })],
plugins: [..., nodeResolve({ exportConditions: [..., 'workerd'] })],
// don't try to bundle cloudflare:sockets
external: [..., 'cloudflare:sockets'],
})
Expand All @@ -57,7 +62,7 @@ config. For example:
```js
await esbuild.build({
...,
conditions: [..., 'cloudflare'],
conditions: [..., 'workerd'],
})
```

Expand Down
2 changes: 1 addition & 1 deletion packages/pg-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"exports": {
".": {
"cloudflare": {
"workerd": {
"import": "./esm/index.mjs",
"require": "./dist/index.js"
},
Comment on lines +14 to 17
Copy link
Contributor

Choose a reason for hiding this comment

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

I would keep both for backward compatibility

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given that the cloudflare condition was only added very recently and seems broken for most people using it, I would be in favour of removing it. We don't want to encourage others to use this as an export condition for Cloudflare Workers.

Copy link

@thomasgauvin thomasgauvin Jun 26, 2025

Choose a reason for hiding this comment

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

From what we can tell, this was merged in #3482 by @brianc, but in so doing inadvertently broke the majority of Cloudflare projects given that workerd is the export condition expected

Expand Down
2 changes: 1 addition & 1 deletion packages/pg-esm-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"type": "module",
"scripts": {
"test": "node --test --conditions=cloudflare"
"test": "node --test --conditions=workerd"
},
"keywords": [
"postgres",
Expand Down