-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[🐞] Qwik bundling PrismaClient on the client when it should only be on the server #3736
Comments
Start a new pull request in StackBlitz Codeflow. |
Move |
tried it same, issue |
heres an updated starter where I tried a few variations. in my project moving to a new file gave the same errors, in this case I'm actually getting a different error (one I've been hitting in my project too) https://stackblitz.com/edit/qwik-starter-3lfrzv?file=src%2Froutes%2Findex.tsx,src%2Fnew-file.ts,src%2Froutes%2Flayout.tsx
|
We have the same issue. |
I wonder how Remix solves it, how can we know we need to remove this line:
? |
I wonder if we could tag it somehow like looking at rollup and other places I see that no one assumes a class instantiation will not have side effects, so we can always close this since it isn't necessarily safe to assume that can be yoinked automatically it's not hard to do new PrismaClient() within server$() each time you need it feel free to close out if you like, this isn't really an issue so much as a hypothetical feature suggestion really |
actually it turns out prisma really doesn't like it when I create all these clients, I keep getting these logs
I can help thing on some kind of alternative pattern. maybe something like:
not actually sure what would happen if I had the above in a file. I guess I could alternatively do something like
or something |
Any clues on any hacks to get this working before Qwik team fixes this. |
@steve8708 I can get your example work with following changes: // routes/index.ts
import { dbClient } from '~/new-file';
const foo = server$(() => {
return dbClient.get();
});
export default component$(() => { ... }); // new-file.ts
class DbClient {
constructor() {
if (typeof window !== 'undefined') {
throw new Error('DB client on client!');
}
}
get() {
console.log('ran fine');
return [];
}
}
export const dbClient = new DbClient(); I forked your stackblitz but it throws a Cross-Site POST error. I believe it's a stackblitz bug, you can clone it and test it locally. |
You need to append file names with |
oh that's an interesting pattern, like if people want additional guarantees/comfort |
I have the same issue. When deploying to Vercel, Netlify or Cloudflare Pages, I get Happens with the example Prisma schema/code you get after you add the prisma integration. I've tried to use custom schemes, different Prisma providers, (I have no issues when running the project locally via |
Which component is affected?
Qwik Optimizer
Describe the bug
I am trying to use prisma with all of the db calls in server$(), but can't because it is being bundled into the browser and throwing errors
Reproduction
https://stackblitz.com/edit/qwik-starter-3lfrzv?file=src%2Froutes%2Findex.tsx
Steps to reproduce
Simply load
/
in the reproduction above. You will see that "DbClient" will be instantiated in the browser, and throw errors, for instance on click.System Info
Additional Information
No response
The text was updated successfully, but these errors were encountered: