Skip to content

[BUG] Can not import .wasm (by @prisma/client/wasm, and other wasm-pack generated) #139

Open
@mizchi

Description

@mizchi

Describe the bug

Opennext and @prisma/client/wasm do not work by import *.wasm.

Prisma does not work on opennext.

$ npm install prisma @prisma/client -D
$ npx prisma --init
# ... edit to use @prisma/client/wasm
$ npx next build
$ npx cloudflare # it works yet
$ wrangler deploy # fail at wrangler's  esbuild
   Creating an optimized production build ...
  Compiled successfully
  Linting and checking validity of types    
  Collecting page data    
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
PrismaClientKnownRequestError: 
Invalid `prisma.post.findMany()` invocation:


Unknown file extension ".wasm" for /home/mizchi/mizchi/next-memo/node_modules/.pnpm/@prisma+client@5.22.0_prisma@5.22.0/node_modules/.prisma/client/query_engine_bg.wasm
    at dr.handleRequestError (/home/mizchi/mizchi/next-memo/node_modules/.pnpm/@prisma+client@5.22.0_prisma@5.22.0/node_modules/@prisma/client/runtime/wasm.js:21:7567)
    at dr.handleAndLogRequestError (/home/mizchi/mizchi/next-memo/node_modules/.pnpm/@prisma+client@5.22.0_prisma@5.22.0/node_modules/@prisma/client/runtime/wasm.js:21:6875)
    at dr.request (/home/mizchi/mizchi/next-memo/node_modules/.pnpm/@prisma+client@5.22.0_prisma@5.22.0/node_modules/@prisma/client/runtime/wasm.js:21:6565)
    at async u (/home/mizchi/mizchi/next-memo/node_modules/.pnpm/@prisma+client@5.22.0_prisma@5.22.0/node_modules/@prisma/client/runtime/wasm.js:30:9560)
    at async I (/home/mizchi/mizchi/next-memo/.next/server/app/page.js:1:39579)
Export encountered an error on /page: /, exiting the build.
  Static worker exited with code: 1 and signal: null
node:internal/errors:983
  const err = new Error(message);

Vite and webpack can handle it but wrangler's esbuild & workerd can not

Steps to reproduce

  • setup prisma
  • import @prisma/client/wasm
import { PrismaClient } from "@prisma/client/wasm";
import { PrismaD1 } from "@prisma/adapter-d1";
import { getCloudflareContext } from "@opennextjs/cloudflare";

export interface Env {
  DB: D1Database;
}

export async function getPrismaClient() {
  try {
    const ctx: any = await getCloudflareContext();
    return new PrismaClient({ adapter: new PrismaD1(ctx.env.DB) });
  } catch (error) {
    console.error("Error getting Prisma client", error);
    throw error;
  }
}

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


### Additional context

This `.wasm`  import style is generated by Rust's `wasm-pack`

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions