Skip to content

Commit 0dfd955

Browse files
fix: ensure that pg-cloudflare can be used with bundlers that don't know about Cloudflare sockets (brianc#2978)
By implementing package.json `exports` we can avoid processing the Cloudflare specific code, which contains `import ... from "cloudflare:sockets"`, in bundlers such as Webpack. If you are bundling for a Worker environment using Webpack then you need to add the `workerd` condition and ignore `cloudflare:sockets` imports: **webpack.config.js** ```js resolve: { conditionNames: ["require", "node", "workerd"] }, plugins: [ new webpack.IgnorePlugin({ resourceRegExp: /^cloudflare:sockets$/, }), ], ```
1 parent 20d2c08 commit 0dfd955

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/pg-cloudflare/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
"name": "pg-cloudflare",
33
"version": "1.1.0",
44
"description": "A socket implementation that can run on Cloudflare Workers using native TCP connections.",
5-
"main": "dist/index.js",
5+
"main": "dist/empty.js",
66
"types": "dist/index.d.ts",
77
"license": "MIT",
88
"devDependencies": {
99
"ts-node": "^8.5.4",
1010
"typescript": "^4.0.3"
1111
},
12+
"exports": {
13+
"workerd": "./dist/index.js",
14+
"default": "./dist/empty.js"
15+
},
1216
"scripts": {
1317
"build": "tsc",
1418
"build:watch": "tsc --watch",

packages/pg-cloudflare/src/empty.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This is an empty module that is served up when outside of a workerd environment
2+
// See the `exports` field in package.json
3+
export default {}

0 commit comments

Comments
 (0)