prisma: [6.6] WebAssembly.instantiate(): Import #0 "./query_compiler_bg.js": module is not an object or function]

Bug description

Nitro + Prisma 6.6.0 + D1 does not work

Severity

๐Ÿšจ Critical: Data loss, app crash, security issue

Reproduction

https://github.com/medz/nitro-prisma-6.6

Expected vs. Actual Behavior

Expected behavior: WASM modules can be parsed normally

Frequency

Consistently reproducible

Does this occur in development or production?

Only in development (e.g., CLI tools, migrations, Prisma Studio)

Is this a regression?

Prisma: 6.6.0 Nitro: 2.11.9 wrangler: 4.10.0

Workaround

Prisma Schema & Queries

datasource db {
  provider = "sqlite"
  url      = env("DATABASE_URL")
}

generator client {
  provider        = "prisma-client"
  output          = "./client/"
  previewFeatures = ["driverAdapters"]
  runtime         = "cloudflare"
}

model Result {
  id        String   @id @default(uuid(7))
  createdAt DateTime @default(now())
}

import { PrismaD1 } from "@prisma/adapter-d1";
import { PrismaClient } from "~/prisma/client";

export default defineEventHandler((event) => {
  const adapter = new PrismaD1(event.context.cloudflare.env.DB as any);
  const client = new PrismaClient({ adapter });
});

Logs & Debug Info

$ nitro dev

 โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
 โ”‚                                                         โ”‚
 โ”‚  ๐Ÿ”ฅ Cloudflare context bindings enabled for dev server  โ”‚
 โ”‚                                                         โ”‚
 โ”‚  Config path: wrangler.toml                             โ”‚
 โ”‚  Persist dir: .wrangler/state/v3                        โ”‚
 โ”‚                                                         โ”‚
 โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ


  โžœ Local:    http://localhost:3000/
  โžœ Network:  use --host to expose

[unwasm] Failed to parse WASM module wasm/query_compiler_bg.sqlite-afbae85635953d66.wasm: Error: [unwasm] Failed to parse wasm/query_compiler_bg.sqlite-afbae85635953d66.wasm: Error: Internal failure: parseVec could not cast the value
    at parseWasm (file:///Users/seven/workspace/panews-api-server/test-prisma/node_modules/unwasm/dist/tools.mjs:6496:11)
    at parse (file:///Users/seven/workspace/panews-api-server/test-prisma/node_modules/unwasm/dist/plugin.mjs:195:22)
    at Object.transform (file:///Users/seven/workspace/panews-api-server/test-prisma/node_modules/unwasm/dist/plugin.mjs:272:73)
    at file:///Users/seven/workspace/panews-api-server/test-prisma/node_modules/rollup/dist/es/shared/node-entry.js:22156:40 {
  [cause]: CompileError2: Internal failure: parseVec could not cast the value
      at parseVec (file:///Users/seven/workspace/panews-api-server/test-prisma/node_modules/unwasm/dist/tools.mjs:5132:19)
      at parseTypeSection (file:///Users/seven/workspace/panews-api-server/test-prisma/node_modules/unwasm/dist/tools.mjs:5148:33)
      at parseSection (file:///Users/seven/workspace/panews-api-server/test-prisma/node_modules/unwasm/dist/tools.mjs:5895:26)
      at Object.decode2 [as decode] (file:///Users/seven/workspace/panews-api-server/test-prisma/node_modules/unwasm/dist/tools.mjs:6169:29)
      at decode2 (file:///Users/seven/workspace/panews-api-server/test-prisma/node_modules/unwasm/dist/tools.mjs:6476:25)
      at parseWasm (file:///Users/seven/workspace/panews-api-server/test-prisma/node_modules/unwasm/dist/tools.mjs:6494:11)
      at parse (file:///Users/seven/workspace/panews-api-server/test-prisma/node_modules/unwasm/dist/plugin.mjs:195:22)
      at Object.transform (file:///Users/seven/workspace/panews-api-server/test-prisma/node_modules/unwasm/dist/plugin.mjs:272:73)
      at file:///Users/seven/workspace/panews-api-server/test-prisma/node_modules/rollup/dist/es/shared/node-entry.js:22156:40
}
โœ” Nitro Server built in 1024ms                                                     nitro 10:46:54
[uncaughtException] [TypeError: WebAssembly.instantiate(): Import #0 "./query_compiler_bg.js": module is not an object or function]

Environment & Setup

  • OS:
  • Database:
  • Node.js version:

Prisma Version

Prisma schema loaded from prisma/schema.prisma
prisma                  : 6.6.0
@prisma/client          : 6.6.0
Computed binaryTarget   : darwin-arm64
Operating System        : darwin
Architecture            : arm64
Node.js                 : v23.9.0
TypeScript              : 5.8.2
Query Engine (Node-API) : libquery-engine f676762280b54cd07c770017ed3711ddde35f37a (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine           : schema-engine-cli f676762280b54cd07c770017ed3711ddde35f37a (at node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm             : @prisma/prisma-schema-wasm 6.6.0-53.f676762280b54cd07c770017ed3711ddde35f37a
Default Engines Hash    : f676762280b54cd07c770017ed3711ddde35f37a
Studio                  : 0.511.0

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 6
  • Comments: 32 (8 by maintainers)

Most upvoted comments

+1 Same issue here

Image

Running NextJS 15@canary with nodeMiddleware: true

I just have encounterd this problem. since once updgraded to v6.6 from v6.5, even if v6.5 re-install, application keep crashโ€ฆ

my environment is cloudflare pages and uses cloudflare-next-on-pagesโ€ฆ

WebAssembly.Instance(): Import #0 "./query_engine_bg.js" "__wbindgen_string_get": function import requires a callable

I was able to reproduce the error based on the reproduction repository:

Image

Interestingly, when I tried downgrading to version 6.5.0, I got this error as well:

Image

Question based on the monorepo example: Is there an expectation that youโ€™d need to build your prisma package before importing? Iirc, the other guides demonstrate being able to import without a build step in /package/prisma

This is not necessarily needed. Hereโ€™s another example using Turborepo where the package containing Prisma definitions isnโ€™t built. The trick is to use exports map: https://github.com/prisma/prisma-examples/blob/79440c034c91d6614c4849c8cedfede4a1cb7902/generator-prisma-client/nextjs-starter-webpack-turborepo/packages/database/package.json#L5-L8

@jkomyno Really appreciate you looking into this. This is working now ๐Ÿ™

For anyone else experiencing this:

  • I removed vite-tsconfig-paths from my Vite config
  • Updated all my imports to be relative path
  • Updated my prisma schema to use provider = "prisma-client"
    • And everything else needed for prisma-client

So far so good. Thank you!


Question based on the monorepo example: Is there an expectation that youโ€™d need to build your prisma package before importing? Iirc, the other guides demonstrate being able to import without a build step in /package/prisma

I updated my prisma configuration to match the monorepo example but Im still seeing this error:

Invalid `prisma.users.findUnique()` invocation:


Cannot find module '/var/task/node_modules/@prisma/client/runtime/query_compiler_bg.postgresql.wasm'

Fwiw. I am using Turborepo and Vite. Not sure to what extent those would affect the output.

@jacek-prisma We are happy to announce that this issue has been resolved. My configuration:

generator experimental {
  provider        = "prisma-client"
  previewFeatures = ["driverAdapters", "queryCompiler"]
  output          = "../src/generated/prisma"
  runtime         = "workerd"
}
import { PrismaClient } from '../../generated/prisma';
import type { SecretsStoreSecret } from '@cloudflare/workers-types';
import { PrismaPlanetScale } from '@prisma/adapter-planetscale';

type Env = { DATABASE_URL: SecretsStoreSecret };

export default {
  async fetch(_: Request, env: Env) {
    const adapter = new PrismaPlanetScale({
      url: await env.DATABASE_URL.get(),
    });
    // @ts-expect-error
    const prisma = new PrismaClient({ adapter });
    const topics = await prisma.topic.findMany({ take: 3 });

    return Response.json(topics);
  },
};

However, there is still a problem with prisma-client. PrismaClient does not support the adapter parameter, but this does not affect the use of the function.

It is worth noting that the package size of the same code once reached 3033.04 KiB / gzip: 1054.53 KiB, but now it is only 2273.59 KiB / gzip: 803.94 KiB, which is a very big improvement.๐Ÿ‘

It is very noteworthy that this does not exist in prisma 6.5 and everything works fine. This problem only occurs after upgrading to 6.6.

You also switched to the experimental new generator, not just upgraded. Does the issue occur for you in the old prisma-client-js generator on 6.6?

@aqrln

No, I tried again the other day to upgrade to Prisma 6.6.0 and continued to use the prisma-client-js generator.

Everything works fine now.