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

[BUG] pg-cloudflare dist isn't copied to .worker-next #150

Open
gwenshap opened this issue Dec 5, 2024 · 1 comment
Open

[BUG] pg-cloudflare dist isn't copied to .worker-next #150

gwenshap opened this issue Dec 5, 2024 · 1 comment
Labels
bug Something isn't working triage

Comments

@gwenshap
Copy link

gwenshap commented Dec 5, 2024

Describe the bug

I have a project that uses opennextjs/cloudflare and also pg-node.

When running npm run preview:worker, I get:

✘ [ERROR] Build failed with 1 error:

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

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

    The module "./dist/index.js" was not found on the file system:

      .worker-next/.next/standalone/node_modules/pg-cloudflare/package.json:13:15:
        13 │     "workerd": "./dist/index.js",
           ╵                ~~~~~~~~~~~~~~~~~

    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.

I discovered that this is because the build step does not copy all files in node_modules/pg-cloudflare/dist/ to .worker-next/.next/standalone/node_modules/pg-cloudflare/dist. It only copies empty.js, but as you can see, more is required.

Changing the build script to:
cloudflare && cp node_modules/pg-cloudflare/dist/* .worker-next/.next/standalone/node_modules/pg-cloudflare/dist
fixed the issue for me, but thats obviously a hack and the cloudflare build should be fixed.

Steps to reproduce

  1. Clone the example here https://github.com/niledatabase/niledatabase/tree/cloudflare_example/examples/integrations/cloudflare/nextjs_example (it is a bit of an overkill for this issue, but it does reproduce it)
  2. npm run preview:worker

Expected behavior

Expected the build to include all files that are necessary to run the app on workerd.
Including all the files from node_modules/pg-cloudflare/dist

@opennextjs/cloudflare version

0.2.1

Node.js version

20.17.0

Wrangler version

3.92.0

next info output

Node.js v20.17.0

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 20.17.0
  npm: 10.8.2
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.0.3 // Latest available version is detected (15.0.3).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: N/A
Next.js Config:
  output: N/A

Additional context

No response

@gwenshap gwenshap added bug Something isn't working triage labels Dec 5, 2024
@himanshu-ntml
Copy link

himanshu-ntml commented Dec 6, 2024

I had the same issue. To fix it, I had to update the package.json file for the "pg-cloudflare" package. Specifically, I modified the exports section as follows:

"exports": {
    "workerd": "./dist/index.js",
    "default": "./dist/index.js"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

2 participants