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

Preview feature feedback: Deno support (deno) #15844

Open
janpio opened this issue Oct 17, 2022 · 31 comments
Open

Preview feature feedback: Deno support (deno) #15844

janpio opened this issue Oct 17, 2022 · 31 comments
Assignees
Labels
domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/feedback Issue for gathering feedback. topic: deno topic: previewFeatures Issue touches on an preview feature flag

Comments

@janpio
Copy link
Contributor

janpio commented Oct 17, 2022

Please share your feedback about the deno functionality released in v4.5.0 in this issue.

The current state of our implementation is described here: #2452 (comment)

  • If you encounter a bug, please open a bug report in this repo.
  • If the feature is working well for you, please share this in a comment below or leave a 👍 on this issue.

If you have any questions, don't hesitate to ask them in the #orm-help channel in the Prisma Slack.

@janpio janpio added kind/feedback Issue for gathering feedback. topic: previewFeatures Issue touches on an preview feature flag domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. topic: deno labels Oct 17, 2022
@seashairo

This comment was marked as outdated.

@janpio

This comment was marked as outdated.

@seashairo
Copy link

That worked \o/

As a follow-up, is there any way to generate a client for Deno without using Data Proxy? I can see that the output dir has a deno folder but it has no generated files without passing --data-proxy.

@janpio
Copy link
Contributor Author

janpio commented Oct 18, 2022

Not yet, no - that is the next phase we will be working on together with the Deno team. Not having a local engine file made adding support much easier (as we could build on our Edge Client), so we started with that. We are optimistic the other variant will work as well though, and we will add that to this preview feature (and announce it in our release notes when it happens).

For now we are happy about any feedback about using Prisma Client for Data Proxy with Deno 🦖

@karelklima
Copy link

Feedback for deno 1.26.2 and prisma 4.5.0-dev.49, running on Windows 10:

  • prisma init works
  • prisma generate sort of works
    • when --data-proxy arg is missing it does not do anything Deno-related and generates regular javascript client
    • when --data-proxy arg is present it prompts to add output to schema when running in Deno
    • when --data-proxy arg is present and output is set in schema it generates files in the appropriate directory
  • generated client does not work and errors with The preview feature "deno" is not known.

In addition, the commands generate the following warnings in console:

napi_add_env_cleanup_hook is currently not supported
Warning: Not implemented: ChildProcess.prototype.disconnect

@janpio
Copy link
Contributor Author

janpio commented Oct 18, 2022

Thanks for the detailled list!

  • when --data-proxy arg is missing it does not do anything Deno-related and generates regular javascript client

That is currently expected, see my explanation above: #15844 (comment) (In hindsight we could have disabled generate without --data-proxy - maybe we will do that soon if we can not follow up with the full functionality soon)

  • generated client does not work and errors with The preview feature "deno" is not known.

That should not be the case any more now - it was while Data Proxy deployed the new version. If you keep getting this when final 4.5.0 is out, please let me know and we will investigate.

In addition, the commands generate the following warnings in console:

napi_add_env_cleanup_hook is currently not supported
Warning: Not implemented: ChildProcess.prototype.disconnect

These are known and something for Deno to fix. No functionality is impacted by this as far as we know. (I'll try to find out how and if they are tracking this in issues so we can link to them.)

@janpio
Copy link
Contributor Author

janpio commented Oct 18, 2022

Now that it is officially out, I described the current state of what this feature is in this comment to the feature request: #2452 (comment)

@denniske

This comment was marked as outdated.

@janpio

This comment was marked as outdated.

@denniske
Copy link

Works fine 👍 Thx!

@karelklima

This comment was marked as outdated.

@patryk-smc
Copy link

I have been using this since yesterday, and it works pretty well for my simple project. Thank you for doing this. Some feedback - from most to least important:

  • Most importantly: it would be great to be able to run this locally without Prisma Data Platform. For this particular project, I'm working 100% locally, and it is never going to be deployed. I could just work with local Postgres or even SQLite.

  • There are some warnings:

    • During prisma generate: napi_add_env_cleanup_hook is currently not supported
    • During prisma generate and prisma push: Warning: Not implemented: ChildProcess.prototype.disconnect
  • Ergonomics could be better, I'm not a fan of running app with npx dotenv --

  • Also, I don't like having package.json or node_modules but assume that this is necessary?

@janpio
Copy link
Contributor Author

janpio commented Oct 19, 2022

All valid points and on our list @patryk-smc 👍

Most importantly: it would be great to be able to run this locally without Prisma Data Platform. For this particular project, I'm working 100% locally, and it is never going to be deployed. I could just work with local Postgres or even SQLite.

We are very aware of that and that will be our big second iteration of the deno preview feature.

There are some warnings:
...

Those are limitations in Deno right now, fortunately, they do not seem to impact functionality.

Ergonomics could be better, I'm not a fan of running app with npx dotenv --

That is honestly more an oversight (which we noticed quite late) and we will fix that.

Also, I don't like having package.json or node_modules but assume that this is necessary?

Agreed. For now it is necessary, but I just replied here how we will hopefully be able to fix that: #2452 (comment)

@patryk-smc
Copy link

Hey, @janpio do you have any eta for being able to use Prisma Deno without data platform?

@janpio
Copy link
Contributor Author

janpio commented Nov 18, 2022

No, unfortunately not. We are both working on it.

@chrisirhc
Copy link

Ergonomics could be better, I'm not a fan of running app with npx dotenv --

Looks like this is no longer needed once you import dotenv from the stdlib from any file that requires the .env file to be loaded:
See https://github.com/denoland/deno_std/tree/bba790ecd4aaaeb4ec739a91121f0c79b1dd988b/dotenv#auto-loading

I tried this with the seed.ts and it worked for me.

@gbahamondezc
Copy link

gbahamondezc commented Nov 30, 2022

Ergonomics could be better, I'm not a fan of running app with npx dotenv --

Looks like this is no longer needed once you import dotenv from the stdlib from any file that requires the .env file to be loaded: See https://github.com/denoland/deno_std/tree/bba790ecd4aaaeb4ec739a91121f0c79b1dd988b/dotenv#auto-loading

I tried this with the seed.ts and it worked for me.

Exactly same behaviour here, no need to use dotenv just replacing normal postgresql connection string in my .env by the DataProxy url and seed worked properly ❤️

@yarabramasta
Copy link

yarabramasta commented Dec 3, 2022

I had a problem with the generator inside docker.

I guess node/npm is necessary to be installed. I tried it before with my own machine, it works smoothly even with npx, the code does generate, if I try on docker, it always fail due to prisma client not being installed.

I'm running on deno 1.28.3 and prisma 4.7.0

@janpio
Copy link
Contributor Author

janpio commented Dec 3, 2022

Can you share the steps you are following exactly @yarabramasta so we can reproduce this? I have an idea waht might be going on here, but with a reproduction we can really look at it.

@yarabramasta
Copy link

Can you share the steps you are following exactly @yarabramasta so we can reproduce this? I have an idea waht might be going on here, but with a reproduction we can really look at it.

Sorry for my late responses. Here is the detail what i'm talking about.

schema.prisma

generator client {
  provider = "prisma-client-js"
  output = "../gen/client"
  previewFeatures = ["deno"]
}

datasource db {
  provider = "mysql"
  url = env("DATABASE_URL")
  relationMode = "prisma"
}

model User {
  id String @id @default(cuid())

  @@map("users")
}

Result on my own machine

[yarabramasta@yb-archx64 api]$ yarn -v && npm -v
1.22.19
8.19.2
[yarabramasta@yb-archx64 api]$ deno run -A --unstable npm:prisma db push
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": MySQL database "urbanlamp" at "ap-southeast.connect.psdb.cloud:3306"

The database is already in sync with the Prisma schema.

Running generate... (Use --skip-generate to skip the generators)
✔ Generated Prisma Client (4.7.1 | library) to ./gen/client in 214ms

Warning: Not implemented: ChildProcess.prototype.disconnect
[yarabramasta@yb-archx64 api]$ ls -al gen/client
total 40472
drwxr-xr-x 4 yarabramasta yarabramasta     4096 Dec  6 09:32 .
drwxr-xr-x 3 yarabramasta yarabramasta     4096 Dec  6 09:32 ..
drwxr-xr-x 2 yarabramasta yarabramasta     4096 Dec  6 09:32 deno
-rw-r--r-- 1 yarabramasta yarabramasta     3916 Dec  6 09:32 index-browser.js
-rw-r--r-- 1 yarabramasta yarabramasta    54069 Dec  6 09:32 index.d.ts
-rw-r--r-- 1 yarabramasta yarabramasta     5492 Dec  6 09:32 index.js
-rwxr-xr-x 1 yarabramasta yarabramasta 41346976 Dec  6 09:32 libquery_engine-debian-openssl-3.0.x.so.node
-rw-r--r-- 1 yarabramasta yarabramasta      110 Dec  6 09:32 package.json
drwxr-xr-x 2 yarabramasta yarabramasta     4096 Dec  6 09:32 runtime
-rw-r--r-- 1 yarabramasta yarabramasta      270 Dec  6 09:32 schema.prisma

My machine had node & npm installed.

Dockerfile

FROM denoland/deno:alpine as migration

WORKDIR /app

COPY prisma .

ARG DATABASE_URL

RUN deno run -A --unstable npm:prisma db push --skip-generate
RUN deno run -A --unstable npm:prisma generate

FROM denoland/deno:alpine as main

WORKDIR /app

RUN chown deno:deno /app

USER deno

COPY --from=migration /app/node_modules .
COPY --from=migration /app/gen .
COPY --from=base /app/deps.ts .

ADD . .

ENV HOSTNAME=0.0.0.0
ENV PORT=4000

EXPOSE ${PORT}

FROM main as dev

ENV NODE_ENV=development

CMD ["run", "--watch", "--allow-net", "--allow-read", "--allow-env", "cmd/main.ts"]

Result from docker build

Docker build command

docker build -t org.bram.urbanlamp:api --build-arg DATABASE_URL .

Result from build

Prisma schema loaded from schema.prisma
Datasource "db": MySQL database "urbanlamp" at "ap-southeast.connect.psdb.cloud:3306"

The database is already in sync with the Prisma schema.

Warning: Not implemented: ChildProcess.prototype.disconnect
Removing intermediate container 07b9f3b9bb30
 ---> 2fe72fec5911
Step 10/27 : RUN deno run -A --unstable npm:prisma generate
 ---> Running in 6a13b2764926
Prisma schema loaded from schema.prisma
napi_add_env_cleanup_hook is currently not supported
✔ Created ./package.json
Error: Command failed with ENOENT: npm install -D [email protected]
No such file or directory (os error 2)
The command '/bin/sh -c deno run -A --unstable npm:prisma generate' returned a non-zero code: 1

As you can see, the migration is successful, but not for the generated code. And my point is, deno container cannot see the npm executable Error: Command failed with ENOENT: npm install -D [email protected]

@yarabramasta
Copy link

yarabramasta commented Dec 6, 2022

I tried this before, but no luck. And as far as I'm concern, this is a bad practice if you want to keep your image stay tiny.

FROM node:alpine as migration

ARG DATABASE_URL

WORKDIR /app

COPY prisma .

RUN npm init -y
RUN npm install -D prisma && npm install @prisma/client
RUN npx prisma db push

FROM denoland/deno:alpine as main

WORKDIR /app

COPY --from=migration /app/package*.json .

# this would cause an error, because you generate with npm (and npm use node) not with `deno run`
# so the `gen` folder wouldn't generate.
COPY --from=migration /app/gen .

RUN mkdir gen

# not recommended & even tho you access the @prisma directory and use it's generated code,
# it still doesn't work, i guess it's not generate the `deno` folder,
# or it had something to-do with the module
COPY --from=migration /app/node_modules/@prisma ./gen

I'm just an intermediate, so please correct or suggest me for this workaround if you have advice.

@janpio
Copy link
Contributor Author

janpio commented Dec 6, 2022

No, this makes sense. For now Prisma CLI did not remove or adapt all the assumptions that it might have about npx or npm being present. We will need to figure those out and find better solutions 👍

@Jolg42
Copy link
Contributor

Jolg42 commented Jan 10, 2023

Deno implemented napi_add_env_cleanup_hook, so the napi_add_env_cleanup_hook is currently not supported warning should be gone in their next release I think
denoland/deno#16925

@Jolg42
Copy link
Contributor

Jolg42 commented Jan 10, 2023

There is an issue about the Warning: Not implemented: ChildProcess.prototype.disconnect warning here
denoland/deno#17265

@HansKristoffer
Copy link

When using the Dockerfile from @yarabramasta we now get the following error:

=> ERROR [migration 5/5] RUN deno run -A --unstable npm:[email protected] generate --data-proxy                                                                                                                                                                            51.3s
------                                                                                                                                                                                                                                                                       
 > [migration 5/5] RUN deno run -A --unstable npm:[email protected] generate --data-proxy:                                                                                                                                                                                        
#9 0.601 Download https://registry.npmjs.org/prisma/-/prisma-4.7.0.tgz                                                                                                                                                                                                       
#9 0.649 Download https://registry.npmjs.org/@prisma/engines/-/engines-4.7.0.tgz                                                                                                                                                                                             
#9 44.95 Environment variables loaded from .env                                                                                                                                                                                                                              
#9 44.98 Prisma schema loaded from prisma/schema.prisma                                                                                                                                                                                                                      
#9 51.20 Error: Command failed with ENOENT: npm install -D [email protected]
#9 51.20 No such file or directory (os error 2)
------
executor failed running [/bin/sh -c deno run -A --unstable npm:[email protected] generate --data-proxy]: exit code: 1

Any idea why this is happening?
I'm running on deno 1.28.3 and prisma 4.7.0

Dockerfile

FROM denoland/deno:1.30.3 as migration

WORKDIR /app

COPY . ./

ARG DATABASE_URL

RUN deno run -A --unstable npm:prisma
RUN deno run -A --unstable npm:[email protected] generate --data-proxy

@halvardssm
Copy link

Is there any way currently to use this without data proxy? This would be a vital step to use it locally with for example SQLite

@mandado
Copy link

mandado commented May 31, 2023

I'm having the same problem of @halvardssm, but I trying to use with planetscale

@fro-profesional
Copy link

I started to get the following error

deno run -A --unstable npm:[email protected]  generate --data-proxy
Prisma schema loaded from prisma/schema.prisma
✔ Created ./package.json

added 2 packages, and audited 3 packages in 1s

found 0 vulnerabilities

added 2 packages, and audited 5 packages in 1s

found 0 vulnerabilities

✔ Installed the @prisma/client and prisma packages in your project
Error: Generator "/Users/franciscoramos/Documents/clau/code/clau/node_modules/@prisma/client/generator-build/index.js" failed:

error: could not find npm package for 'file:///Users/franciscoramos/Documents/clau/code/clau/node_modules/@prisma/client/generator-build'

I tried with

and same error, what is weird is that It was working just fine, but all of a sudden made a schema change, and generate command stop working, even for new empty schemas with just user class

My schema

generator client {
    provider        = "prisma-client-js"
    previewFeatures = ["deno"]
    output          = "./generated/client"
}

datasource db {
    provider  = "mongodb"
    url       = env("PROXY_DB_URL")
    directUrl = env("DB_URL")
}

model users {
    // Base
    uuid      String    @id @default(uuid()) @map("_id")
    createdAt DateTime? @default(now())
    updatedAt DateTime? @updatedAt()

    // Data
    email String?
    phone String?
    name  String?
}

@fro-profesional
Copy link

fro-profesional commented Jun 22, 2023

I found that it was a Prisma issue (I think)

having these specific versions of Prisma fixed the issue

"devDependencies": { 
    "prisma": "^4.15" 
  },
"dependencies": { 
    "@prisma/client": "^4.11" 
 }

mmmm also have to downgrade to deno 1.34.1 so maybe a deno issue? denoland/deno#19590

@janpio
Copy link
Contributor Author

janpio commented Aug 11, 2023

@HansKristoffer Right now Prisma via Deno CLI still needs npm installed as it needs to run npm install prisma and npm install @prisma/client so they are present in a local node_modules. We are trying to improve that. If you ran RUN npm install -D prisma && npm install @prisma/client before, that should not be necessary anymore. That is why @yarabramasta has that in his Dockerfile: #15844 (comment)

@halvardssm Not yet, working on it.
@mandado PlanetScale should work via Prisma Data Proxy or Accelerate.

@fro-profesional I think that is just random, sometimes generate crashes and then it just works. I reported an issue for my case to Deno: denoland/deno#20099 (For me it crashes the first time with a specific error message, then second and further runs just work)

@janpio
Copy link
Contributor Author

janpio commented Aug 11, 2023

Update: Prisma without Data Proxy is now "usable" in Deno. Still rough corners, but we are getting there: #2452 (comment)

@janpio janpio removed their assignment Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/feedback Issue for gathering feedback. topic: deno topic: previewFeatures Issue touches on an preview feature flag
Projects
None yet
Development

No branches or pull requests