Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 BUG: vitest integration error with @prisma/adapter-d1: no such module error (#wasm-engine-loader) #5685

Open
mgcrea opened this issue Apr 22, 2024 · 1 comment
Labels
bug Something that isn't working

Comments

@mgcrea
Copy link

mgcrea commented Apr 22, 2024

Which Cloudflare product(s) does this pertain to?

Workers Vitest Integration

What version(s) of the tool(s) are you using?

3.51.2

What version of Node are you using?

20.12.0

What operating system and version are you using?

macOS Sonoma 14.4.1

Describe the Bug

Observed behavior

When running vitest with a test that leverages the @prisma/adapter-d1, I'm hit with the following import error:

Error: No such module "Users/olivier/Projects/cloudflare/cloudflare-hono-worker/node_modules/.prisma/client/#wasm-engine-loader".
    at Object.getQueryEngineWasmModule (Users/olivier/Projects/cloudflare/cloudflare-hono-worker/node_modules/.prisma/client/wasm.js?mf_vitest_no_cjs_esm_shim:182:5)
    at Users/olivier/Projects/cloudflare/cloudflare-hono-worker/node_modules/@prisma/client/runtime/wasm.js?mf_vitest_no_cjs_esm_shim:11:731
    at Object.loadLibrary (Users/olivier/Projects/cloudflare/cloudflare-hono-worker/node_modules/@prisma/client/runtime/wasm.js?mf_vitest_no_cjs_esm_shim:11:975)
    at gt.loadEngine (Users/olivier/Projects/cloudflare/cloudflare-hono-worker/node_modules/@prisma/client/runtime/wasm.js?mf_vitest_no_cjs_esm_shim:11:3194)
    at gt.instantiateLibrary (Users/olivier/Projects/cloudflare/cloudflare-hono-worker/node_modules/@prisma/client/runtime/wasm.js?mf_vitest_no_cjs_esm_shim:11:2778) {
  clientVersion: '5.12.1'
}

Expected behavior

Test with @prisma/adapter-d1 should work

Steps to reproduce

export const usersRoutes = new Hono<{ Bindings: Bindings }>()
  .post("/", zValidator("json", userSchema), async (c) => {
    const body = c.req.valid("json");
    const env = c.env!;
    const adapter = new PrismaD1(env.DB);
    const prisma = new PrismaClient({ adapter });
    const user = await prisma.user.create({ data: body });
    return c.json(user, 201);
  })

test:

import { env } from "cloudflare:test";
import { testClient } from "hono/testing";
import { describe, expect, test } from "vitest";
import { usersRoutes } from "./usersRoutes";

describe("usersRoutes", () => {
  const client = testClient(usersRoutes, env);

  test("POST / is ok", async () => {
    // const ctx = createExecutionContext();
    const res = await client.index.$post({
      json: { name: "John Doe", email: "jdoe@gmail.com" },
    });
    // await waitOnExecutionContext(ctx);
    expect(res.status).toBe(201);
    expect(await res.json()).toMatchObject({ id: expect.any(Number), name: "John Doe" });
  });
});

Can be fixed with this change in wasm.js:

config.engineWasm = {
  getRuntime: () => require('./query_engine_bg.js'),
  getQueryEngineWasmModule: async () => {
    return (await import('./query_engine_bg.wasm')).default // <-- fix
  }
}

but probably breaking other things!

Related issue

prisma/prisma#23911

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

Error: No such module "Users/olivier/Projects/cloudflare/cloudflare-hono-worker/node_modules/.prisma/client/#wasm-engine-loader".
    at Object.getQueryEngineWasmModule (Users/olivier/Projects/cloudflare/cloudflare-hono-worker/node_modules/.prisma/client/wasm.js?mf_vitest_no_cjs_esm_shim:182:5)
    at Users/olivier/Projects/cloudflare/cloudflare-hono-worker/node_modules/@prisma/client/runtime/wasm.js?mf_vitest_no_cjs_esm_shim:11:731
    at Object.loadLibrary (Users/olivier/Projects/cloudflare/cloudflare-hono-worker/node_modules/@prisma/client/runtime/wasm.js?mf_vitest_no_cjs_esm_shim:11:975)
    at gt.loadEngine (Users/olivier/Projects/cloudflare/cloudflare-hono-worker/node_modules/@prisma/client/runtime/wasm.js?mf_vitest_no_cjs_esm_shim:11:3194)
    at gt.instantiateLibrary (Users/olivier/Projects/cloudflare/cloudflare-hono-worker/node_modules/@prisma/client/runtime/wasm.js?mf_vitest_no_cjs_esm_shim:11:2778) {
  clientVersion: '5.12.1'
}
@mgcrea mgcrea added the bug Something that isn't working label Apr 22, 2024
@vladinator1000
Copy link

vladinator1000 commented Apr 29, 2024

I also hit this bug (also mentioned #5127 (comment)).

Here's a full reproduction repo https://github.com/vladinator1000/prisma-vitest-miniflare/tree/27410822df6161c2d97006352fe74dbd0692e90e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
Status: Untriaged
Development

No branches or pull requests

2 participants