Hey, since 2.26.0 I cannot create a prisma client ...
# orm-help
a
Hey, since 2.26.0 I cannot create a prisma client by using
nApi
:
Copy code
Error: invalid type: boolean `true`, expected a string
      at LibraryEngine.loadEngine (node_modules/@prisma/client/runtime/index.js:23613:27)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at LibraryEngine.instantiateLibrary (node_modules/@prisma/client/runtime/index.js:23557:7)
Anyone got any idea why? When not using
nApi
it works fine.
r
Could you share your
schema.prisma
? I tried upgrading from
2.26.0
to
2.27.0
and ran
prisma generate
with
nApi
and works fine on a sample schema.
a
Thanks for the quick response! Yes, one sec
Copy code
generator client {
  provider        = "prisma-client-js"
  binaryTargets   = ["native", "rhel-openssl-1.0.x", "linux-musl"]
  previewFeatures = ["nApi"]
}

datasource postgresql {
  provider = "postgresql"
  url      = env("POSTGRES_URL")
}
And then the data model (
enum
,
model
, etc) which I will not share šŸ™‚ sorry!
Can it be related to one of the model definitions? It works fine with 2.24.1
r
Possibly. I would suggest creating an issue here as I cannot reproduce this. Tried it on a sample schema:
Copy code
generator client {
  provider        = "prisma-client-js"
  binaryTargets   = ["native", "rhel-openssl-1.0.x", "linux-musl"]
  previewFeatures = ["nApi"]
}

datasource postgresql {
  provider = "postgresql"
  url      = env("POSTGRES_URL")
}

model User {
  id   Int    @id @default(autoincrement())
  name String
}
a
Gotcha, thanks a lot @Ryan
šŸ‘ 1
r
Does it work with the above model? If so, then you can confirm this, but you would have to share the model with us privately so that we can check.
a
Yup. I think it's coming from the model
I'll try to investigate and will post here if I find anything interesting
šŸ’Æ 2
Like, which model was broken and what fixed it
šŸ‘ 2
j
Really interested in figuring this out, as using Node-API should not have any influence on this at all. So something would be very amiss if it does.
a
I think I was mistaken, possibly; Why is there a difference between 2.24.1 and 2.27.0 (and 2.26.0) in the output target of
prisma generate
? I mean to ask: is this a change that was done on purpose? 2.24.1:
Copy code
Prisma schema loaded from schema.prisma

āœ” Generated Prisma Client (2.24.1) to ./../../node_modules/@prisma/client in 1.15s
You can now start using Prisma Client in your code. Reference: <https://pris.ly/d/client>
import { PrismaClient } from '@prisma/client' const prisma = new PrismaClient()``` 2.26.0 and 2.27.0:
Copy code
Prisma schema loaded from schema.prisma

:heavy_check_mark: Generated Prisma Client (2.27.0) to ./node_modules/@prisma/client in 529ms
You can now start using Prisma Client in your code. Reference: <https://pris.ly/d/client>
import { PrismaClient } from '@prisma/client' const prisma = new PrismaClient()```
Where
schema.prisma
was not changed between the versions
I'm trying to add
Copy code
output = "../../node_modules/@prisma/client"
But there are some other problems which I don't yet understand
So when I'm modifying the
output
in
schema.prisma
I'm receiving the following error:
Copy code
Error: Cannot find module './runtime'
What's weird is that if I'm removing
nApi
from preview features it works fine 😐
I'll try to reproduce something basic maybe with a fresh workspace
j
That sounds like a good idea.
Are you using a monorepo, maybe with
pnpm
by chance? We fixed and changed a few of the path detections there, and this looks like a possible side effect. What exactly happens there in all configuration - and even what is supposed to happen - is not super well understood šŸ˜•
a
Hey, sorry for the delay! Using monorepo yes, but with yarn workspaces and not pnpm.
I still don't understand myself how to reproduce, but I'm trying to
šŸ‘ 1
@janpio just an update, I have bumped to 2.28.0 and now I'm getting a different error:
Copy code
{
  "code": "InvalidArg",
  "clientVersion": "2.28.0"
}
Found it!
It's a bug I think
What happens is that one of my env vars is defined with
true
(not a string), it causes Prisma to go šŸŒšŸŒ
Not sure how to reproduce it, I think that
serverless
patches
process
but I might be wrong
In any case, only when using napi, if in
runtime/index.js
I'm changing the initialization of
QueryEngineConstructor
, such that the
env
parameter has some boolean value, it fails. For example:
Copy code
try {
              this.engine = new this.QueryEngineConstructor({
                datamodel: this.datamodel,
                env: { DATABASE_URL: process.env.DATABASE_URL, AAA: true },
...
Then it fails with the same error
Sorry - process.env should be
Record<string, string>
, it's not a bug in Prisma but rather something else transforms the boolean string to boolean values along the way. Anyway this was the issue, thanks for the help!
I do think that the prisma client doesn't need all of the env variables anyway
OK last update from me šŸ˜„ Turns out that at least serverless-plugin-offline changes
process.env.IS_OFFLINE
to be
true
(e.g. boolean and not a string), so prisma + serverless-plugin-offline won't play well together sadly (see this line)
Do you think it makes sense to open a PR where the prisma client receives an optional
env
mapping to override
process.env
?