-
Notifications
You must be signed in to change notification settings - Fork 133
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
does not work
#605
Comments
Hello is there any workaround for this issue? I try to use pg and prisma on cloudflare next-on-pages with nextjs application. Observe similar issue. |
This build error comes from Next.js and is something we have no control over. |
@janpio / @VanThanh12195 have you found a workaround? |
@james-elicx can you provide tips what a developer can/should do fix it? |
|
@james-elicx I understand that the build error is coming from nextjs. However, lets focus on a possible solution or a workaround to use Or just declare that |
Has anyone solved this problem? |
There might be a way to make it work by configuring Next.js and patching |
Not working pg connection, MariaDB connection and MySQL connection in to middleware.ts |
If you're trying to get |
Has anybody yet been able to get the Cloudflare version of OpenNext to work with prisma? The following prisma configuration works fine with import { Pool } from "pg";
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "@prisma/client";
const pool = new Pool({ connectionString: connectionString, max: 1 })
const adapter = new PrismaPg(pool)
const prisma = new PrismaClient({ adapter }) Error messages:
and
Adding pg-cloudflare as a dependency does also not seem to help. |
having same issue as above ^ |
@maltekuehl were you able to figure this out? @irvinebroque do you have an example of using @opennextjs/cloudflare with prisma to get it working? |
Btw - not an expert by any means, but I had managed to get supabase (postgres) working with the neon driver from prisma, not sure if that's helpful, but might be worth a shot until pg is working? |
@karthikjn01 could you give me an example of how you set it up? |
Unfortunately don't have the code on hand. Have a look here: https://www.prisma.io/docs/orm/overview/databases/neon |
@karthikjn01 i just tried it using the neon drivers and got this error same issue as above. What does your package.json look like? |
Ah yeah, I was running into that on opennext - try next-on-pages, I believe that's where it was working. |
hi yes thank you @karthikjn01 i got it working with next-on-pages, thank you. It looks like it sstill bugged on opennext |
I seem to have gotten it compiling and running with prisma pool, but ther seems to be approx 1 second overhead for each function call made, as I think the setting up of the PrismaClient with the adapter takes around a second each time to instantiate. @karthikjn01 have you had any of those issues? The moment i moved it back to a singleton (to test this theory) it worked fine |
I also encountered this problem and couldn't work together. |
|
@ianthpun @yzqzy I have solved this issue. The reason for this error is that the
const fs = require("fs");
const path = require("path");
// Base destination directory
const destNodeModules = path.join(
".worker-next",
".next",
"standalone",
"node_modules"
);
const sourceNodeModules = path.join("node_modules");
const files = [
".prisma/client/wasm.js",
".prisma/client/wasm-worker-loader.mjs",
".prisma/client/query_engine_bg.wasm",
".prisma/client/query_engine_bg.js",
"@prisma/client/runtime",
];
// Copy runtime directory recursively
function copyRecursive(src, dest) {
const exists = fs.existsSync(src);
const stats = exists && fs.statSync(src);
const isDirectory = exists && stats.isDirectory();
if (isDirectory) {
fs.mkdirSync(dest, { recursive: true });
fs.readdirSync(src).forEach(function (childItemName) {
copyRecursive(
path.join(src, childItemName),
path.join(dest, childItemName)
);
});
} else {
try {
fs.copyFileSync(src, dest);
} catch (error) {
console.warn(error);
}
}
}
try {
// Copy additional files
for (const file of files) {
copyRecursive(
path.join(sourceNodeModules, file),
path.join(destNodeModules, file)
);
}
console.log(
"Successfully copied Prisma runtime files and additional WASM files"
);
} catch (err) {
console.error("Error copying Prisma files:", err);
process.exit(1);
} |
next-on-pages environment related information
Description
pg
has support for Cloudflare Workers and Pages.This project makes it possible to run Next.js projects on Cloudflare Pages.
Unfortunately something gets lost along the way, so that
pg
triggers webpack errors duringbuild
anddev
:I theorize that the problem is because
pg
was made to use a adapter version of some code when running inworkerd
. But during the Next.js build this is not set, so it thinks it is running in a normal Node environment and includes the wrong code - which then would not work inedge-light
which the Next.js bundler assumes for edge functions - and hence fails.Reproduction
https://github.com/janpio/cloudflare-next-prisma/tree/plain-pg
Pages Deployment Method
Direct Upload (
wrangler pages publish
or the @cloudflare/pages-action GitHub Action)Pages Deployment ID
No response
Additional Information
No response
Would you like to help?
The text was updated successfully, but these errors were encountered: