pg-cloudflare does not work with vite-plugin-cloudflare
What versions & operating system are you using?
wrangler v22.16.0, vite-plugin @1.7.2
Please provide a link to a minimal reproduction
No response
Describe the Bug
pg-cloudflare is using "cloudflare" export condition
https://github.com/brianc/node-postgres/blob/master/packages/pg-cloudflare/package.json#L14-L17
However plugin has hardcoded "workerd" condition and does not allow change it
https://github.com/cloudflare/workers-sdk/blob/main/packages/vite-plugin-cloudflare/src/cloudflare-environment.ts#L128
See also https://github.com/brianc/node-postgres/issues/3493
Please provide any relevant error logs
No response
This was an issue on my end - not related to vite, I'm just running wrangler.
This was an issue on my end - not related to vite, I'm just running wrangler.
I just tried wrangler and it worked fine for me. Maybe was broken with earlier version.
It is definitely broken on the latest wrangler 4.20.5 (in my case when using beta remote bindings) and is solved by patching pg-cloudflare
diff --git a/package.json b/package.json
index f0d277340fb57ea7caab3c9dd6408d92ca03361f..59839662842c57d944885de56bb05104c922b51a 100644
--- a/package.json
+++ b/package.json
@@ -15,6 +15,10 @@
"import": "./esm/index.mjs",
"require": "./dist/index.js"
},
+ "workerd": {
+ "import": "./esm/index.mjs",
+ "require": "./dist/index.js"
+ },
"default": "./dist/empty.js"
}
},
Broken with wrangler sdk, both dev and remote modes
please fix, huge blocker, don't care to patch the application
I'll open a PR to fix this today.
~~I will add cloudflare as a default condition so that users don't need to add it but~~ user provided conditions already get merged with the defaults if you set them at the environment level.
export default defineConfig({
environments: {
[your_worker_environment_name]: {
resolve: {
conditions: ["cloudflare"]
}
}
},
plugins: [cloudflare()]
});
See https://developers.cloudflare.com/workers/vite-plugin/reference/vite-environments/ for more info about configuring Vite Environments. You can use this as a workaround until the fix is released.
Having discussed this internally, adding the cloudflare condition on our side isn't the correct fix here. workerd is the standard export condition for Cloudflare Workers, as specified by WinterCG - https://runtime-keys.proposal.wintercg.org/#workerd.
Please use the workaround above for now and we'll open a PR to pg-cloudflare to use workerd instead.
This happens outside vite too, I don't use vite (pure wrangler dev) and see this error
Yes, the label vite-plugin assigned to this issue seems incorrect
The workaround in Wrangler until pg-cloudflare is updated is to run the command with WRANGLER_BUILD_CONDITIONS=cloudflare,workerd,worker,browser set.
This has been fixed in [email protected] ([email protected]).