Skip to content

fix: avoid return loaded prisma if undefined #461

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

Merged
merged 1 commit into from
Jun 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/runtime/src/enhancements/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ function loadPrismaModule(prisma: any) {
if (prisma._engineConfig?.datamodelPath) {
const loadPath = path.dirname(prisma._engineConfig.datamodelPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Azzerty23 , thanks a lot for making this PR!

I'm trying to reproduce the issue with the repo you shared (express-api project) but things seem to work well from my environment. I added a line of log to print the prisma._engineConfig?.datamodelPath and it's like:

`<root>/node_modules/.prisma/client/schema.prisma`

, and loading the module from that folder works (since it contains Prisma generated code there)...

So I'm still struggling to understand what could have caused failure on your side. Do you mind adding a similar line of log in your environment and seeing what it prints? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much! I think I have understood the issue. In my build script, I copy the schema.prisma to my dist/ folder to avoid this warning:
Capture d’écran 2023-06-05 à 14 45 21
Solution from: prisma/prisma#10512 (comment)

Copying the schema.prisma to my dist/ folder prevents prisma._engineConfig?.datamodelPath from recognizing the correct path for the Prisma client.

Indeed, when I console.log prisma._engineConfig?.datamodelPath, I get:

/Users/augustin/Documents/Dev/Test/zenstack-rest-turbo/apps/express-api/dist/schema.prisma

That's why I only had this issue with my built project. However, I don't understand why you didn't encounter the same problem with my repo. Ideally, I would like to find a solution to avoid the warning altogether but it's not blocking.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I tried running npm run dev to trigger the copy of schema.prisma into dist folder, even after that, things are still running well. And I never saw that Prisma warning. Very weird ...

Anyway, I think your PR is still a good one to make things more resilient. I'm going to merge it.

try {
return require(loadPath).Prisma;
const _prisma = require(loadPath).Prisma;
if (typeof _prisma !== 'undefined') return _prisma;
return require('@prisma/client/runtime');
} catch {
return require('@prisma/client/runtime');
}
Expand Down