Prisma client looks in root directory (C:\) for engine binary when used with Next.js
See original GitHub issueBug description
When importing the Prisma client into a Next.js project, calls to functions like findOne
throw an error like this:
Invalid `prisma.account.findOne()` invocation in
C:\Users\Robbie\Code\prisma-bug-test\next-app\node_modules\next\dist\next-server\server\api-utils.js:8:7
Query engine binary for current platform "windows" could not be found.
This probably happens, because you built Prisma Client on a different platform.
(Prisma Client looked in "\query-engine-windows.exe")
Files in \:
$GetCurrent
$Recycle.Bin
$WinREAgent
Config.Msi
Documents and Settings
DumpStack.log
DumpStack.log.tmp
hiberfil.sys
Intel
IntelOptaneData
pagefile.sys
PerfLogs
Program Files
Program Files (x86)
ProgramData
Python38
Recovery
swapfile.sys
System Volume Information
Users
Windows
Windows10Upgrade
To solve this problem, add the platform "windows" to the "generator" block in the "schema.prisma" file:
generator client {
provider = "prisma-client-js"
binaryTargets = ["native"]
}
Adding binaryTargets = ["native"]
does not help, since the problem is that Prisma looks in the root directory for its binaries. I can only guess that the reason that this bug only shows up in Next.js and not regular Node environments is that Next.js uses Webpack and Babel, which may transform the code and break hacks like eval("require('path')")
found in the Prisma node engine code.
How to reproduce
Clone this repo and follow the instructions in the README.
Expected behavior
There should be no error, and the findOne
function should return null.
Prisma information
The schema can be found in the reproduction repo.
Environment & setup
- OS: Windows
- Database: PostgreSQL (although I doubt this matters since the query engine doesn’t load in the first place)
- Node.js version: 12.16.3
- Prisma version:
@prisma/cli : 2.8.1
Current platform : windows
Query Engine : query-engine 439da16b2f8314c6faca7d2dad2cdcf0732e8a9c (at node_modules\@prisma\cli\query-engine-windows.exe)
Migration Engine : migration-engine-cli 439da16b2f8314c6faca7d2dad2cdcf0732e8a9c (at node_modules\@prisma\cli\migration-engine-windows.exe)
Introspection Engine : introspection-core 439da16b2f8314c6faca7d2dad2cdcf0732e8a9c (at node_modules\@prisma\cli\introspection-engine-windows.exe)
Format Binary : prisma-fmt 439da16b2f8314c6faca7d2dad2cdcf0732e8a9c (at node_modules\@prisma\cli\prisma-fmt-windows.exe)
Studio : 0.296.0
Preview Features : atomicNumberOperations
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Best practice for instantiating PrismaClient with Next.js
This in turn initializes a new PrismaClient instance each time due to hot reloading that creates a connection to the database. This can...
Read more >Dockerize NextJS Application with Prisma - Stack Overflow
I've found the error. I think it's a problem with the M1 Chip. I changed node:16-alpine3.12 to node:lts and added some commands to...
Read more >Prisma Client Binary Not Copied for Netlify Lambda Functions ...
(Prisma Client looked in "/query-engine-rhel-openssl-1.0.x") You already added ... able to pass into the build by using netlify-lambda build functions -c .
Read more >prisma argument of type whereuniqueinput needs at least one ...
I am not entirely certain, but prisma returns a JS object... So perhaps a query like this should work: const ...
Read more >Troubleshooting Node.js Deploys - Heroku Dev Center
Heroku will output which binaries (ie. node , npm ) are used for each ... it may be better to exclude a lib...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@janpio I’ve updated my repository to the latest version (2.14.0) and the error message is different now. It shows:
If you clone the repository again and repeat the instructions inside you should be able to reproduce this new error.
I’m a bit busy at the moment but I’ll get to it when I can.