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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(driver-adapters-wasm): describe failing Qwik + Vercel Edge scenarios #5203

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

jkomyno
Copy link
Contributor

@jkomyno jkomyno commented Jul 12, 2024

DO NOT MERGE

This PR describes the failing scenario of Qwik City + Vercel Edge + Wasm driverAdapters.

The turso-vercel-qwik-edgemw project in this PR exposes an endpoint, /demo/users, which invokes Prisma Client + Turso and returns a JSON object with some preloaded database results.

Notably, this setup requires using the vercel-edge adapter for Qwik City: https://qwik.dev/docs/deployments/#adapters-and-middleware.

The TL/DR of the scenario is: in order to run a Qwik City app on Vercel Edge, one needs a custom Vite plugin, which apparently is only used on deployed apps (so not on local pnpm build + pnpm dev). For Vercel Edge, this plugin canonically lives in ./adapters/vercel-edge/vite.config.ts. There's no known way of making this scenario work.

None of the approaches mentioned in prisma/prisma#21094 or QwikDev/qwik#4075 led to successful results, but here are some findings related to ./adapters/vercel-edge/vite.config.ts:

  • This plugin works locally, but fails at compile time when deploying this project with vercel:

    // ./adapters/vercel-edge/vite.config.ts
    
    import { vercelEdgeAdapter } from "@builder.io/qwik-city/adapters/vercel-edge/vite";
    import { extendConfig } from "@builder.io/qwik-city/vite";
    import baseConfig from "../../vite.config";
    
    export default extendConfig(baseConfig, () => {
      return {
        build: {
          ssr: true,
          rollupOptions: {
            input: ["./src/entry.vercel-edge.tsx", "@qwik-city-plan"],
          },
          outDir: ".vercel/output/functions/_qwik-city.func",
        },
        plugins: [
          vercelEdgeAdapter(),
        ],
      };
    });

    Local runtime output:

    Screenshot 2024-07-12 at 17 02 23

    Compilation failure on Vercel:

    TypeError [PLUGIN_ERROR]: Invalid module ".prisma/client/default" is not a valid package name imported from /vercel/path0/.vercel/output/functions/_qwik-city.func/@qwik-city-plan.js
  • @Jolg42 had mentioned in [🐞]Building Prisma with Vercel-Edge generates compile errors QwikDev/qwik#4075 (comment) that the following worked for him:

    // ./adapters/vercel-edge/vite.config.ts
    
    import { vercelEdgeAdapter } from "@builder.io/qwik-city/adapters/vercel-edge/vite";
    import { extendConfig } from "@builder.io/qwik-city/vite";
    import baseConfig from "../../vite.config";
    
    export default extendConfig(baseConfig, () => {
      return {
        build: {
          ssr: true,
          rollupOptions: {
            input: ["src/entry.vercel-edge.tsx", "@qwik-city-plan"],
          },
          outDir: ".vercel/output/functions/_qwik-city.func",
        },
        plugins: [vercelEdgeAdapter()],
        resolve: {
          alias: {
            ".prisma/client/default": "./node_modules/.prisma/client/default.js",
            "./query_engine_bg.wasm?module": "./node_modules/.prisma/client/query_engine_bg.wasm?init",
          },
        },
      };
    });

    Unfortunately that's not the case for me. However, by slightly tweaking the resolve block to

    {
      alias: {
        ".prisma/client/default": "./node_modules/@prisma/client/index.js",
      },
    }

    I was at least able to deploy on Vercel. Compilation works fine, but at runtime, /demo/users returns error 500.
    Looking at the Vercel logs, I see the following error:

    TypeError: Ju.PrismaClient is not a constructor
    Screenshot 2024-07-12 at 16 18 46

The problems potentially lie in 3 different code areas:

Problem resolution feedback is welcome.


Internal: environment variables like DRIVER_ADAPTERS_TURSO_VERCEL_QWIK_EDGEMW_PROJECT_ID and DRIVER_ADAPTERS_TURSO_VERCEL_QWIK_EDGEMW_DATABASE_URL are not yet set by the CI, but I think that's beside the point. The screenshots I've posted come from a private Vercel account of mine. I'd be happy if somebody could set those private tokens for me, but I unfortunately don't expect to see a green CI after that.

@jkomyno jkomyno requested a review from SevInf July 12, 2024 15:13
@jkomyno jkomyno requested review from janpio and a team as code owners July 12, 2024 15:13
@jkomyno jkomyno requested review from Druue and removed request for a team, janpio and Druue July 12, 2024 15:13
Comment on lines +186 to +193
export const onGet: RequestHandler = async ({ json, env }) => {
const prisma = getPrisma(env)

const regResult = await getResult(prisma).catch((error) => ({ error_in_regResult: error.message }))
const itxResult = await prisma.$transaction(getResult).catch((error: Error) => ({ error_in_itxResult: error.message }))

json(200, { itxResult, regResult })
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for /demo/users/ lives here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant