prisma: Qwikcity: Error during build for Vercel Edge

Bug description

".prisma/client/index-browser" is imported by ".prisma/client/index-browser?commonjs-external", but could not be resolved – treating it as an external dependency.

error during build:
TypeError [PLUGIN_ERROR]: Invalid module ".prisma/client/index-browser" is not a valid package name imported from /Users/harshmangalam/qwik-prisma/.vercel/output/functions/_qwik-city.func/assets/@qwik-city-plan-2c65295d.js
    at new NodeError (node:internal/errors:399:5)
    at parsePackageName (node:internal/modules/esm/resolve:817:11)
    at packageResolve (node:internal/modules/esm/resolve:840:5)
    at moduleResolve (node:internal/modules/esm/resolve:938:20)
    at defaultResolve (node:internal/modules/esm/resolve:1153:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36)

How to reproduce

  • pnpm qwik add vercel-edge
  • pnpm run build

Expected behavior

No response

Prisma information

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
}

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

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
}


import { PrismaClient } from "@prisma/client";

export const prisma = new PrismaClient();

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: v18.16.0

Prisma Version

5.3.1

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 2
  • Comments: 15 (10 by maintainers)

Most upvoted comments

I ran into this issue when working with CloudFlare pages.

Invalid module ".prisma/client/edge" is not a valid package name

import { PrismaClient } from '@prisma/client/edge';

I found this link that helped me fix it: https://fixtergeek.com/blog/how-to-use-prismaclient-with-qwik-on-cloudflare-pages-2023

vite.config.ts

export default defineConfig(() => {
  return {
    ...
    resolve: {
      alias: {
        ".prisma/client/edge": "./node_modules/.prisma/client/edge.js"
      }
    }
  };
});

If you’re using PNPM, the Prisma Client may not be in node_modules/.prisma, but you can change the output directory in schema.prisma.

generator client {
  provider = "prisma-client-js"
  output = "../node_modules/.prisma/client"
}

I can confirm this:

npm create qwik@latest
npm run qwik add prisma
npm run qwik add vercel-edge

Two problems:

  • @prisma/client currently does not work on Edge Functions, including Vercel Edge Functions or Runtime. Reproduction see: https://github.com/janpio/prisma-qwik
  • Even using the supposedly compatible @prisma/client/edge does not work out of the box:
    ".prisma/client/edge" is imported by ".prisma/client/edge?commonjs-external", but could not be resolved – treating it as an external dependency.
    error during build:
    TypeError [PLUGIN_ERROR]: Invalid module ".prisma/client/edge" is not a valid package name imported from C:\Users\Jan\Documents\throwaway\qwik\.vercel\output\functions\_qwik-city.func\assets\@qwik-city-plan-382afed5.js
        at new NodeError (node:internal/errors:387:5)
        at parsePackageName (node:internal/modules/esm/resolve:777:11)
        at packageResolve (node:internal/modules/esm/resolve:800:5)
        at moduleResolve (node:internal/modules/esm/resolve:901:20)
        at defaultResolve (node:internal/modules/esm/resolve:1115:11)
        at nextResolve (node:internal/modules/esm/loader:163:28)
        at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)
        at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
        at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
        at link (node:internal/modules/esm/module_job:75:36)
    
    Reproduction see https://github.com/janpio/prisma-qwik/tree/data-proxy

@harshmangalam You original problem is expected right now, as Prisma does not support Vercel Edge Functions out of the box which Qwik’s vercel-edge uses. You can follow this issue here for updates on this: https://github.com/prisma/prisma/issues/20566

The second problem is unexpected and something we might want to investigate independently - I will keep this issue for that.

@harshmangalam for pnpm you will need to try something like this:

     ".prisma/client/default":
          "./node_modules/.pnpm/@prisma+client@5.15.0-dev.62_prisma@5.15.0-dev.62/node_modules/@prisma/client/default.js",

@Jolg42 It works for me when using npm but got following errors with pnpm.

error during build:
Error: [commonjs--resolver] Could not load ./node_modules/.prisma/client/default.js: ENOENT: no such file or directory, open './node_modules/.prisma/client/default.js'

I found out that this could be solved with 2 aliases, see my repro here: https://github.com/Jolg42/prisma-repro-21094

This is what worked for me: https://github.com/Jolg42/prisma-repro-21094/blob/main/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",
      },
    },
  };
});

I found out about this in Vite’s docs here https://vitejs.dev/guide/features#webassembly

Pre-compiled .wasm files can be imported with ?init.

@harshmangalam @blakeley @eglove Could you try that and let us know if that works for you too?

Note: I found the related issues in qwik’s repo:

Our release 5.11.0 just added preview support for edge function deployments, please take a look if this helps resolving this issue: https://github.com/prisma/prisma/releases/tag/5.11.0

I had the same issue above (and resolved it with the same resolution above). I just attempted to upgrade to 5.11.0 and I’m now getting a similar issue:

TypeError [PLUGIN_ERROR]: Invalid module ".prisma/client/default" is not a valid package name imported from ~/.vercel/output/functions/_qwik-city.func/q-xwzqvYfN.js

I tried a similar fix, but it did not resolve the issue:

export default defineConfig(() => {
  return {
    ...
    resolve: {
      alias: {
        ".prisma/client/default": "./node_modules/.prisma/client/default.js",
      }
    }
  };
});

Instead, I get the following error:

error during build:
RollupError: Unexpected eof
    at getRollupEror (file:///~/node_modules/rollup/dist/es/shared/parseAst.js:375:41)