question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma client looks in root directory (C:\) for engine binary when used with Next.js

See original GitHub issue

Bug 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:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
RobbieGMcommented, Jan 16, 2021

@janpio I’ve updated my repository to the latest version (2.14.0) and the error message is different now. It shows:

error - ../database/prisma/generated/client/runtime/index.js:59322:0
Module not found: Can't resolve 'string_decoder/'
  59320 |     if (options.encoding) {
  59321 |       if (!StringDecoder)
> 59322 |         StringDecoder = require("string_decoder/").StringDecoder;
  59323 |       this.decoder = new StringDecoder(options.encoding);
  59324 |       this.encoding = options.encoding;
  59325 |     }
Error from chokidar (C:\): Error: EBUSY: resource busy or locked, lstat 'C:\DumpStack.log.tmp'
Error from chokidar (C:\): Error: EBUSY: resource busy or locked, lstat 'C:\hiberfil.sys'
Error from chokidar (C:\): Error: EBUSY: resource busy or locked, lstat 'C:\pagefile.sys'
Error from chokidar (C:\): Error: EBUSY: resource busy or locked, lstat 'C:\swapfile.sys'

If you clone the repository again and repeat the instructions inside you should be able to reproduce this new error.

1reaction
RobbieGMcommented, Jan 15, 2021

I’m a bit busy at the moment but I’ll get to it when I can.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found