Skip to content
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

fix: ensure that pg-cloudflare can be used with bundlers that don't know about Cloudflare sockets #2978

Merged
merged 1 commit into from May 31, 2023

Conversation

petebacondarwin
Copy link
Collaborator

@petebacondarwin petebacondarwin commented May 16, 2023

Fixes #2975

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

  resolve: { conditionNames: ["require", "node", "workerd"] },
  plugins: [
    new webpack.IgnorePlugin({
      resourceRegExp: /^cloudflare:sockets$/,
    }),
  ],

…now about Cloudflare sockets

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$/,
    }),
  ],
```
@brianc
Copy link
Owner

brianc commented May 31, 2023

@petebacondarwin you still working on this (it's set to draft) - getting repeated issues about this & I'd love to help get this one merged in.

@petebacondarwin petebacondarwin marked this pull request as ready for review May 31, 2023 15:39
@petebacondarwin
Copy link
Collaborator Author

Oh sorry. I thought it was set to ready.
This works for me. It would be good if those hitting the issue could try it

@brianc
Copy link
Owner

brianc commented May 31, 2023

Ah great thanks! I'll go ahead & get it released & follow up on the linked issues. ❤️

@brianc brianc merged commit 0dfd955 into brianc:master May 31, 2023
15 checks passed
@IqbalLx
Copy link

IqbalLx commented Jun 1, 2023

what about vite ?

@Feuerhamster
Copy link

what about vite ?

+1

@petebacondarwin
Copy link
Collaborator Author

@IqbalLx and/or @Feuerhamster - please could you provide a simple reproduction of a problem you have with this library and Vite so that I can debug it and find a solution.

@petebacondarwin petebacondarwin deleted the webpack-fix branch June 1, 2023 16:07
thijs pushed a commit to thijs/node-postgres that referenced this pull request Aug 1, 2023
…now 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$/,
    }),
  ],
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v8.11.0 UnhandledSchemeError when bundling with Webpack
4 participants