webcontainer-core icon indicating copy to clipboard operation
webcontainer-core copied to clipboard

Prisma generate failed

Open tomrbroderick opened this issue 3 years ago • 14 comments
trafficstars

Describe the bug

Prisma migration failed with the error: request to https://binaries.prisma.sh/all_commits/f352a33b70356f46311da8b00d83386dd9f145d6/debian-openssl-1.1.x/migration-engine.gz.sha256 failed, reason: socket hang up

Link to the blitz that caused the error

https://stackblitz.com/~/github.com/tomrbroderick/chicken-event-service

Steps to reproduce

Go to pr.new for the repo

Expected behavior

Repo loads up correctly

Parity with Local

Screenshots

No response

Platform

Version = 1.67.0
Hash = 69b9b1602da27b7f44e9800c223182ce1a037ea8
WebContainer = 3c06ff333fff62d153837b0d0df85b8ed07b008f

Browser name  = Chrome
Full version  = 100.0.4896.127
Major version = 100
navigator.appName = Netscape
navigator.userAgent = Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36
performance.memory = {
  "totalJSHeapSize": 95891497,
  "usedJSHeapSize": 67858325,
  "jsHeapSizeLimit": 2172649472
}

Additional context

No response

tomrbroderick avatar Oct 18 '22 20:10 tomrbroderick

:wave: @tomrbroderick Can you provide a repro in an public repo?

jrvidal avatar Oct 19 '22 10:10 jrvidal

Not sure if running Prisma is possible inside WebContainer

  • https://github.com/prisma/prisma/issues/7185
  • https://github.com/prisma/prisma/issues/7187

adrianbienias avatar Oct 23 '22 14:10 adrianbienias

Have the same issue with Lucia Auth, which uses Prisma under the hood. Check out my issue here: https://github.com/pilcrowOnPaper/lucia-auth/issues/186

There you will find a reproduction link. I hope that Prisma will work anytime soon.

carstenjaksch avatar Oct 31 '22 15:10 carstenjaksch

Hey there! This is a CORS issue, because https://binaries.prisma.sh doesn't allow arbitrary origins, that's why you're seeing a socket hang up. But even if we worked around that, Prisma won't work in WebContainer unless native binaries are compiled to JS/Wasm as a browser can't run binaries.

d3lm avatar Dec 16 '22 08:12 d3lm

Prisma is tracking Stackbliz/Webcontainer compatibility here now: https://github.com/prisma/prisma/issues/17710

With a Chrome extension to enable CORS you can download the engines now when installing Prisma via Npm, and since version 4.10.0 of Prisma also run prisma generate as we moved most logic to a Wasm module! Most other CLI commands that use the Migration Engine still crash though (as it uses a binary engine) and the default Prisma Client also crashes as it uses a Node-API library (which is still too much like a binary for this environment).

We also have Prisma Data Platform with the Data Proxy, but there for now we are again hitting CORS and preflights limitations. I can overcome these with an elaborate local setup (Chrome extension + local SSL proxy to simulate a working preflight request) - but I will hopefully be able to make all that much easier soon. I'll keep you updated.

janpio avatar Feb 11 '23 22:02 janpio

Wow, that's pretty cool. Thanks for giving an update on the progress! Very exciting and and awesome work @janpio 👏

d3lm avatar Feb 22 '23 15:02 d3lm

Just an FYI @janpio We have experimental support for a CORS proxy which is currently behind a feature flag so at some point when this goes live there is no need for using a Chrome extension.

Can you give an update on WebContainer compatibility for Prisma? Is this being actively worked on that there's Wasm-based alternatives for the native addons? @Brooooooklyn is also working on a WASI target for napi-rs and there's also https://github.com/toyobayashi/emnapi from @toyobayashi that has Wasm support. Those two are potentially useful when you have native addons you'd like to compile to Wasm.

It'd be really nice if users could use Prisma in WebContainer and both of our user bases could mutually benefit from it. Is there something that we can help with?

d3lm avatar Jan 04 '24 12:01 d3lm

A built-in proxy would indeed help a lot.

We are currently working on a Workers compatible version of Prisma Client that will use a Wasm module, but the problem with other CLI commands that use the schema engine will not be solved via that. That engine currently also needs to talk to databases via TCP socket connections, so we are a bit in a pickle here how to move forward.

janpio avatar Jan 10 '24 00:01 janpio

Oh I see. Potentially what you could do for the TCP socket is to use TCP over WebSocket maybe. This is not something that we currently support out of the box and definitely something we want to add but I don't know when that will be. Neon does something similar where they have a driver that uses a WebSocket / TCP proxy for the TCP connection instead. This works well in WebContainer today. So maybe the engine can then use another driver which is WebSocket based?

Check out https://github.com/neondatabase/serverless

d3lm avatar Jan 10 '24 12:01 d3lm

I am aware of Neon and their serverless driver, but that would require a server side component to open and hold those Websocket connections. We have something similar on an HTTP level with Prisma Accelerate which actually works just fine on Stackblitz 👍

The problem here is that migrations (which the schema engine is responsible for) via these "proxies" are a hard problem to solve and also not something that is usually needed for the default use cases of Prisma Accelerate. (With Neon for example you are also expected to do the migrations via a direct TCP socket connection.)

But we'll get there, sooner or later some way.

janpio avatar Jan 10 '24 14:01 janpio

Ok, thanks for the update @janpio 🙏 Makes sense.

d3lm avatar Mar 11 '24 19:03 d3lm