altv-js-module icon indicating copy to clipboard operation
altv-js-module copied to clipboard

PrismaJS not working since process.chdir cannot be used in workers

Open Phill030 opened this issue 1 year ago • 6 comments

Description of the problem

When trying to use PrismaJS, you'll instantly get the error, that process.chdir() is not supported in workers. The only workaround for that right now, is to use the wsl, which would be very laborious to setup just for one project.

Reproduction steps

  1. install PrismaJS within a project.
  2. fix the N-API error, by setting engineType = "binary" in the client in your schema
  3. generate your prisma client using yarn prisma generate or npx prisma generate
  4. start your server

Expected behaviour

There should be no error saying

[18:07:36][Error] Uncaught exception: Error: 
Invalid `prisma.account.count()` invocation:

process.chdir() is not supported in workers

Additional context

No response

Operating system

Windows 10

Version

15.0-dev79

Scope

server

Reproduction tested

  • [X] I confirm that I have made sure that this issue is also present on the newest dev version

Phill030 avatar Apr 29 '23 16:04 Phill030

Aslong as you need to set engineType = "binary" I dont recommend using Prisma within the alt:V serverside context, it makes prisma setup a local websocket server to communicate with their rust query builder rather than using the node ffi api and it is drasticaly slower.

yannbcf avatar Apr 29 '23 16:04 yannbcf

So this would theoretically need to be fixed by alt:V?

Phill030 avatar Apr 29 '23 18:04 Phill030

Yes

JamessDev avatar May 02 '23 18:05 JamessDev

any updates on this issue?

15322107 avatar Jul 03 '23 15:07 15322107

@15322107 https://discord.com/channels/371265202378899476/371271006360436757/1146704764751577152

Leon — 08/31/2023 10:14 AM And no there is no fix planned, ask the nodejs devs to make it work xd <...> alt:V uses a completely standard nodejs build It doesn't have a single line of the source code modified, but it doesn't work because ¯\_(ツ)_/¯

Although if you're not querying the database 1000 times per second, that "drastically slower" performance is really not an issue. For loading/saving the player and doing occasional query for some menu you might as well could use google sheets and players would notice no difference whatsoever.

Yiin avatar Sep 03 '23 20:09 Yiin

@15322107

any updates on this issue?

I'm using this setup as workaround:

setup-globals.ts

// Until prisma starts supporting ESM, this is the workaround
import { createRequire } from "module";

global.require = createRequire(import.meta.url);
process.chdir = () => {};

Yiin avatar Feb 09 '24 01:02 Yiin