-
Notifications
You must be signed in to change notification settings - Fork 18
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
[BUG] Can not import .wasm
(by @prisma/client/wasm, and other wasm-pack generated)
#139
Comments
.wasm
(by @prisma/client).wasm
(by @prisma/client/wasm)
.wasm
(by @prisma/client/wasm).wasm
(by @prisma/client/wasm, and other wasm-pack generated)
Hi @mizchi, it looks like your issue is caused by Others have solved this problem by adding configuration to |
Good point, can you try adding |
I used those links to verify this by rewriting First I needed to examine the prisma code generation and runtime steps.
I found some problems here.
This is my trial and error. It hasn't completely worked yet, but it worked on hand to the point where it bypasses the initialization of wasm. First, in config.plugins.push(
new webpack.IgnorePlugin({
contextRegExp: /\\.wasm$/,
resourceRegExp: /\\.wasm$/, }
})
); At prisma/client/wasm runtime, modify the code generator to resolve from global variables. diff --git a/generator-build/index.js b/generator-build/index.js
index f0adad1914bb059450d36d8df69acd57f9c95750..056bf25d709c0ca12f0b748d58f2156f54fadec9 100644
--- a/generator-build/index.js
+++ b/generator-build/index.js
@@ -7753,10 +7753,7 @@ function buildQueryEngineWasmModule(wasm, copyEngine, runtimeNameJs) {
return `config.engineWasm = {
getRuntime: () => require('. /query_engine_bg.js'),.
getQueryEngineWasmModule: async () => {
- const queryEngineWasmFilePath = require('path').join(config.dirname, 'query_engine_bg.wasm')
- const queryEngineWasmFileBytes = require('fs').readFileSync(queryEngineWasmFilePath)
-fs'.
- return new WebAssembly.Module(queryEngineWasmFileBytes)
+ return __PRISMA_BINARY;
}
}`;
}
@@ -7764,9 +7761,7 @@ function buildQueryEngineWasmModule(wasm, copyEngine, runtimeNameJs) {
return `config.engineWasm = {
getRuntime: () => require('. /query_engine_bg.js'),.
getQueryEngineWasmModule: async () => {
- const loader = (await import('#wasm-engine-loader')).default
- const engine = (await loader).default
- return engine
+ return __PRISMA_BINARY;
}
}`;
} With this in place, copy import wasm from ". /query_engine_bg.wasm";
globalThis.__PRISMA_BINARY = await WebAssembly.instantiate(wasm);
// ...original This should now work, at least on the Workers runtime. However, we could not verify that this actually works. The reason is that it fails in the prerender phase of the Next App Router. The prerender executes There may be a better way. I will experiment some more. |
Thanks for the detailed analysis! |
Describe the bug
Opennext and
@prisma/client/wasm
do not work by import*.wasm
.Prisma does not work on opennext.
Vite and webpack can handle it but wrangler's esbuild & workerd can not
Steps to reproduce
@prisma/client/wasm
npx wrangler deploy
Expected behavior
@prisma/client
works on opennext.@opennextjs/cloudflare version
0.2.1
Node.js version
22.x
Wrangler version
3.88.0
next info output
Operating System: Platform: linux Arch: x64 Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024 Available memory (MB): 64163 Available CPU cores: 16 Binaries: Node: 22.9.0 npm: 10.8.3 Yarn: N/A pnpm: 9.9.0 Relevant Packages: next: 15.0.3 // Latest available version is detected (15.0.3). eslint-config-next: 15.0.3 react: 18.3.1 react-dom: 18.3.1 typescript: 5.6.3 Next.js Config: output: N/A
The text was updated successfully, but these errors were encountered: