Skip to content
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

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

Closed
RobbieGM opened this issue Oct 8, 2020 · 8 comments
Assignees
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. topic: windows
Milestone

Comments

@RobbieGM
Copy link

RobbieGM commented Oct 8, 2020

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
@pantharshit00
Copy link
Contributor

Hey @RobbieGM

Sorry for the late reply here, I am unable to reproduce this issue withe 2.13.1 release.

Can you please try this again with the latest version?

@RobbieGM
Copy link
Author

RobbieGM commented Jan 1, 2021

Thanks for your reply,

The version you used to attempt to reproduce the bug looks newer than the one I had the bug with. I'll upgrade and let you know if the problem persists.

@pantharshit00 pantharshit00 transferred this issue from prisma/prisma-client-js Jan 13, 2021
@pantharshit00 pantharshit00 added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. topic: windows labels Jan 13, 2021
@janpio
Copy link
Member

janpio commented Jan 14, 2021

Hey @RobbieGM, did you have time to check this again? Would be great so we know if we can close this issue or need to investigate further.

@RobbieGM
Copy link
Author

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

@RobbieGM
Copy link
Author

@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.

@janpio janpio added this to the 2.16.0 milestone Jan 20, 2021
@janpio janpio modified the milestones: 2.16.0, 2.17.0 Feb 3, 2021
@pantharshit00
Copy link
Contributor

@RobbieGM Please have the client generated inside the next project otherwise next will try to bundle built in node core libs resulting the the string_encoder error which is core node js lib.

@RobbieGM
Copy link
Author

What if I want to use the same prisma schema and generated code for two other folders or subprojects? My idea was to put it in a third folder and import it, but this caused the problem I was getting. Since only one of them is a finicky Next.js project and the other is plain JS/TS, I could put it in the Next project and import it from the other one. Is this my best option at this point?

@pantharshit00
Copy link
Contributor

@RobbieGM Solution there is to use a monorepo tool like lerna or nx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. topic: windows
Projects
None yet
Development

No branches or pull requests

3 participants