altv-js-module
altv-js-module copied to clipboard
PrismaJS not working since process.chdir cannot be used in workers
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
- install PrismaJS within a project.
- fix the N-API error, by setting
engineType = "binary"
in the client in your schema - generate your prisma client using
yarn prisma generate
ornpx prisma generate
- 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
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.
So this would theoretically need to be fixed by alt:V?
Yes
any updates on this issue?
@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.
@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 = () => {};