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

Could not resolve "pg-cloudflare" when deploying to CloudFlare Workers #76

Closed
gregavola opened this issue Oct 8, 2024 · 2 comments
Closed

Comments

@gregavola
Copy link

I'm using Prisma as defined here, and I am able to run npm run dev have it working locally to serve content.

Once I run npm run build:worker && wrangler deploy - everything builds, but I get this 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.

✘ [ERROR] Build failed with 2 errors:

.worker-next/.next/standalone/node_modules/.prisma/client/default.js:1:30: ERROR:
Could not resolve "#main-entry-point"
.worker-next/.next/standalone/node_modules/pg/lib/stream.js:41:41: ERROR: Could not
resolve "pg-cloudflare"

import { Pool } from "pg";
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "@prisma/client";

const connectionString = `${process.env.DATABASE_URL}`;

const pool = new Pool({ connectionString });
const adapter = new PrismaPg(pool);
const prisma = new PrismaClient({ adapter });
export default prisma;


```


```
"dependencies": {
    "@aws-sdk/client-sqs": "^3.549.0",
    "@aws-sdk/util-utf8-node": "^3.259.0",
    "@prisma/adapter-pg": "^5.20.0",
    "@prisma/client": "^5.20.0",
    "dayjs": "^1.11.13",
    "next": "14.2.14",
    "pg": "^8.10.0",
    "prisma": "^5.20.0",
    "react": "^18",
    "react-dom": "^18",
    "zod": "^3.23.8"
  },
  "devDependencies": {
    "@opennextjs/cloudflare": "^0.0.3",
    "@types/node": "^20.16.10",
    "@types/pg": "^8.11.10",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "eslint": "^8",
    "eslint-config-next": "14.2.14",
    "postcss": "^8",
    "tailwindcss": "^3.4.1",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2",
    "wrangler": "^3.80.1"
  }

```
@vicb
Copy link
Contributor

vicb commented Oct 8, 2024

Hey @gregavola could you please report your issue at https://github.com/cloudflare/workerd/discussions/categories/npm-package-requests instead.

It would be helpful to add a repo with the failing project.

Thanks

@vicb vicb closed this as completed Oct 8, 2024
@vicb
Copy link
Contributor

vicb commented Oct 8, 2024

(I closed the report because this is related to worked rather than specific to next)

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