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

Error during build because of pg cloudflare #2987

Open
Feuerhamster opened this issue May 26, 2023 · 3 comments
Open

Error during build because of pg cloudflare #2987

Feuerhamster opened this issue May 26, 2023 · 3 comments

Comments

@Feuerhamster
Copy link

We're using the pg package in a project. Recently, we get this error during build process:

error   [vite]: Rollup failed to resolve import "cloudflare:sockets" from "/node_modules/pg-cloudflare/dist/index.js".
  This is most likely unintended because it can break your application at runtime.
  If you do want to externalize this module explicitly add it to
  `build.rollupOptions.external`
Error: [vite]: Rollup failed to resolve import "cloudflare:sockets" from "/node_modules/pg-cloudflare/dist/index.js".

The thing is, we are not using cloudflare or cloudflare workers at all. I saw that the pg-cloudflare package is in the optional dependencies of the pg package. For whatever reason, node installs all optional dependencies by default. So I tried installing the packages without the optional dependencies.

But now there is this error:

✘ [ERROR] Could not resolve "pg-cloudflare"

    node_modules/pg/lib/stream.js:10:41:
      10 │     const { CloudflareSocket } = require('pg-cloudflare')
         ╵                                          ~~~~~~~~~~~~~~~

  You can mark the path "pg-cloudflare" as external to exclude it from the bundle, which will remove
  this error. You can also surround this "require" call with a try/catch block to handle this
  failure at run-time instead of bundle-time.

What did I do wrong?

@charmander
Copy link
Collaborator

#2978 will supposedly improve this. But like the error message says,

You can mark the path "pg-cloudflare" as external to exclude it from the bundle, which will remove this error.

@Feuerhamster
Copy link
Author

This fixed the problem during build but at runtime with client side components it still appears

@charmander
Copy link
Collaborator

Your client-side components shouldn’t be loading pg; even if you can get it to quietly import without errors, that’s a lot of unnecessary code served to clients.

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

No branches or pull requests

2 participants