-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Description
Summary
When using @zama-fhe/relayer-sdk in a Next.js application with output: "standalone", the node-tfhe dependency fails to load its WASM file at runtime.
Environment
@zama-fhe/relayer-sdk: 0.3.0-6node-tfhe: 1.4.0-alpha.3 (transitive dependency)- Next.js: 16.0.10
- Turbopack (Next.js 16 default bundler)
Error
ENOENT: no such file or directory, open '/ROOT/node_modules/node-tfhe/tfhe_bg.wasm'
Root Cause
node-tfhe/tfhe.js uses __dirname to locate its WASM file:
const wasmPath = `${__dirname}/tfhe_bg.wasm`;
const wasmBytes = require('fs').readFileSync(wasmPath);When Next.js bundles this with output: "standalone", __dirname is resolved at build time to a placeholder path (/ROOT/...) instead of the actual runtime path.
Workaround
Add node-tfhe to serverExternalPackages in next.config.ts:
const nextConfig: NextConfig = {
output: "standalone",
serverExternalPackages: [
"node-tfhe",
],
};This prevents Next.js from bundling the package, allowing __dirname to resolve correctly at runtime.
Suggestion
Consider documenting this workaround for Next.js users, or exploring alternative WASM loading strategies that work with bundlers (e.g., using import.meta.url or async WASM imports).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels