unwasm icon indicating copy to clipboard operation
unwasm copied to clipboard

prisma compatibility

Open pi0 opened this issue 1 year ago • 11 comments

Yhere are probably easier ways to include a repro, but I ran in to the same problem with Prismas new database adapters.

Here's a repro-link codesandbox.io.

If you try yourself with prisma, it does require you to have generated the prisma client before building:

node_modules/.bin/prisma generate

Originally posted by @Zn4rK in https://github.com/unjs/unwasm/issues/19#issuecomment-1984137271

pi0 avatar Mar 08 '24 10:03 pi0

FWIW;

That reproduction uses Prismas dev version 5.11.0-dev.5.

When patched with mukundshahs patch, it did build, but it did not work when previewed with Wrangler.

It looks like Prisma 5.11.0 will be released very soon, and should probably have a stabilised wasm path.

When I tried the latest version of 5.11.0 (5.11.0-dev.52), with the patch, I got the following error when building instead:

[nitro 11:29:45 AM]  ERROR  Error: Could not load /SOME_PATH/node_modules/.pnpm/@[email protected][email protected]/node_modules/.prisma/client/query_engine_bg.wasm?module (imported by node_modules/.pnpm/@[email protected][email protected]/node_modules/.prisma/client/wasm-edge-light-loader.js): ENOENT: no such file or directory, open '/SOME_PATH/node_modules/.pnpm/@[email protected][email protected]/node_modules/.prisma/client/query_engine_bg.wasm?module'

The path

/SOME_PATH/node_modules/.pnpm/@[email protected][email protected]/node_modules/.prisma/client/query_engine_bg.wasm

does exists. If I manually remove the querystring (?module), and apply the patch, it does work.

Zn4rK avatar Mar 08 '24 10:03 Zn4rK

The prisma team has some integration tests here that might be helpful: https://github.com/prisma/ecosystem-tests/tree/dev/driver-adapters-wasm

Zn4rK avatar Mar 08 '24 10:03 Zn4rK

Thanks for the updates and info dear @Zn4rK ❤️

pi0 avatar Mar 08 '24 10:03 pi0

Hey everyone, Sehii from Prisma team here. We would really like to support Nitro and Nuxt edge deployments and I did my own short investigation into the problem. You can find basic reporduction of the problem here. Offending code seems to be here - it assumes that import modules are valid JS identifiers which is not what wasm-bindgen does by default - idetifier need to be escaped.

Hope it helps!

SevInf avatar Mar 13 '24 10:03 SevInf

Thanks for the pointer dear @SevInf. I'm going to work on prisma driver integration soon (congrats on last release!) and will investigate this one as well.

(mainly for here we need a minimal reproduction or regression test. if you are able to provide it before me feel free to directly make PR 👍🏼 )

pi0 avatar Mar 13 '24 10:03 pi0

https://github.com/unjs/unwasm/pull/24 landed with a relevant fix. Keeping this issue open until making sure prisma is fully supported.

pi0 avatar Mar 14 '24 15:03 pi0

@pi0 thanks for the fix! I've updated by reproduction to the latest unwasm version. Now we are getting different error:

[unwasm] Failed to parse WASM module wasm/query_engine_bg-5343c5664d9b411c.wasm: Error: [unwasm] Failed to parse wasm/query_engine_bg-5343c5664d9b411c.wasm: Error: Unexpected instruction: 0xc1
    at parseWasm (file:///Users/serhii/projects/unwasm-bug/node_modules/unwasm/dist/tools.mjs:6479:11)
    at parse (file:///Users/serhii/projects/unwasm-bug/node_modules/unwasm/dist/plugin.mjs:195:22)
    at Object.transform (file:///Users/serhii/projects/unwasm-bug/node_modules/unwasm/dist/plugin.mjs:272:73)
    at /Users/serhii/projects/unwasm-bug/node_modules/rollup/dist/shared/rollup.js:998:40 {
  [cause]: CompileError2: Unexpected instruction: 0xc1
      at parseInstructionBlock (file:///Users/serhii/projects/unwasm-bug/node_modules/unwasm/dist/tools.mjs:5351:19)
      at parseInstructionBlock (file:///Users/serhii/projects/unwasm-bug/node_modules/unwasm/dist/tools.mjs:5424:13)
      at parseInstructionBlock (file:///Users/serhii/projects/unwasm-bug/node_modules/unwasm/dist/tools.mjs:5424:13)
      at parseInstructionBlock (file:///Users/serhii/projects/unwasm-bug/node_modules/unwasm/dist/tools.mjs:5424:13)
      at parseInstructionBlock (file:///Users/serhii/projects/unwasm-bug/node_modules/unwasm/dist/tools.mjs:5424:13)
      at parseInstructionBlock (file:///Users/serhii/projects/unwasm-bug/node_modules/unwasm/dist/tools.mjs:5424:13)
      at parseInstructionBlock (file:///Users/serhii/projects/unwasm-bug/node_modules/unwasm/dist/tools.mjs:5424:13)
      at parseInstructionBlock (file:///Users/serhii/projects/unwasm-bug/node_modules/unwasm/dist/tools.mjs:5424:13)
      at parseInstructionBlock (file:///Users/serhii/projects/unwasm-bug/node_modules/unwasm/dist/tools.mjs:5424:13)
      at parseCodeSection (file:///Users/serhii/projects/unwasm-bug/node_modules/unwasm/dist/tools.mjs:5328:11)

0xc1 is a valid wasm instruction, so It looks like @webassmpblyjs/parser is not up to date with a spec.

SevInf avatar Mar 15 '24 14:03 SevInf

yes i guess i need to patch it again 😅 In the meantime, you can use ?module as workaround it will skip parsing.

pi0 avatar Mar 15 '24 14:03 pi0

Hello I would just like to ask if there is any progress on this issue in order to include Prisma ORM into NuxtHub :blush: Thanks for reply

kleinpetr avatar Nov 28 '24 19:11 kleinpetr

I wanted to ask what is the status of this issue, and whether there is a workaround? I have a little Nuxt project, that I want to deploty to Cloudflare, with Prisma, and the D1 database. I have followed the Prisma guide for D1, and can build the app locally, and create tables both locally and remote. But I can not deploy my app to Cloudflare anymore, after adding Prisma. It fails with the message

ERROR  Error: Could not load /Users/agatanoair/workspace/theslope/node_modules/.prisma/client/query_engine_bg.wasm?module (imported by node_modules/.prisma/client/wasm-edge-light-loader.mjs): ENOENT: no such file or directory, open '/Users/agatanoair/workspace/theslope/node_modules/.prisma/client/query_engine_bg.wasm?module'

How to reproduce: code is open source, here is a link to my Github Action error

(ERROR  Error: Could not load /Users/agatanoair/workspace/theslope/node_modules/.prisma/client/query_engine_bg.wasm?module (imported by node_modules/.prisma/client/wasm-edge-light-loader.mjs): ENOENT: no such file or directory, open '/Users/agatanoair/workspace/theslope/node_modules/.prisma/client/query_engine_bg.wasm?module')

Is this a Prisma <-> Nitro compatibility error?

themathmagician avatar Jan 19 '25 23:01 themathmagician

@themathmagician did you find a way to fix this?

andrewdavid48 avatar Mar 23 '25 23:03 andrewdavid48