QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.46k stars 1.26k forks source link

[🐞] Build fails with Prisma and Deno #4747

Open krishna-santosh opened 1 year ago

krishna-santosh commented 1 year ago

Which component is affected?

Qwik Rollup / Vite plugin

Describe the bug

Added Prisma and Deno adapter to Starter App and tried to build with npm run build

Build Failed.

Output:

".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 /home/krishna/Code/Qwik/qwik-app/server/assets/@qwik-city-plan-6181dabb.js
    at new NodeError (node:internal/errors:405:5)
    at parsePackageName (node:internal/modules/esm/resolve:709:11)
    at packageResolve (node:internal/modules/esm/resolve:731:5)
    at moduleResolve (node:internal/modules/esm/resolve:830:20)
    at defaultResolve (node:internal/modules/esm/resolve:1035:11)
    at DefaultModuleLoader.resolve (node:internal/modules/esm/loader:269:12)
    at DefaultModuleLoader.getModuleJob (node:internal/modules/esm/loader:153:32)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:33)
    at link (node:internal/modules/esm/module_job:75:36)

Reproduction

https://stackblitz.com/edit/qwik-starter-2irmfx

Steps to reproduce

npm create qwik@latest cd qwik-app npm install npm run qwik add prisma npm run qwik add deno npm run build

System Info

System:
    OS: Linux 6.3 Arch Linux
    CPU: (4) x64 Intel(R) Core(TM) i3-4005U CPU @ 1.70GHz
    Memory: 698.45 MB / 3.73 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.3.0 - /usr/bin/node
    npm: 9.6.6 - /usr/bin/npm
    pnpm: 8.6.3 - /usr/bin/pnpm
  Browsers:
    Brave Browser: 114.1.52.126
    Chromium: 114.0.5735.133

Additional Information

No response

stackblitz[bot] commented 1 year ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

zwn commented 11 months ago

It is enough to add deno to get a failing build (no need to add prisma).

zwn commented 11 months ago

However the error is different:

Error during SSG
getPlatform is not iterable (cannot read property Symbol(Symbol.iterator))
  Pathname: /
  Plugin: qwik-ssg
  File: /home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:9038:34
  9037|  const RouterOutlet = /* @__PURE__ */ componentQrl(/*#__PURE__*/ inlinedQrl(s_e0ssiDXoeAM, "s_e0ssiDXoeAM"));
  9038|  const QACTION_KEY = "qaction";
  9039|  const resolveHead = (endpoint, routeLocation, contentModules, locale)=>{
     |     ^
  9040|      const head = createDocumentHead();
  9041|      const getData = (loaderOrAction)=>{
      at shim (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:9038:34)
      at AsyncFunction.s_e0ssiDXoeAM (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:9053:24)
      at AsyncFunction.invoke (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:744:46)
      at eval (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:4644:28)
      at then (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:186:79)
      at eval (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:4634:20)
      at eval (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:1332:28)
      at safeCall (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:179:25)
      at executeComponent (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:1332:12)
      at renderSSRComponent (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:1591:6)
krishna-santosh commented 11 months ago

However the error is different:

Error during SSG
getPlatform is not iterable (cannot read property Symbol(Symbol.iterator))
  Pathname: /
  Plugin: qwik-ssg
  File: /home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:9038:34
  9037|  const RouterOutlet = /* @__PURE__ */ componentQrl(/*#__PURE__*/ inlinedQrl(s_e0ssiDXoeAM, "s_e0ssiDXoeAM"));
  9038|  const QACTION_KEY = "qaction";
  9039|  const resolveHead = (endpoint, routeLocation, contentModules, locale)=>{
     |     ^
  9040|      const head = createDocumentHead();
  9041|      const getData = (loaderOrAction)=>{
      at shim (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:9038:34)
      at AsyncFunction.s_e0ssiDXoeAM (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:9053:24)
      at AsyncFunction.invoke (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:744:46)
      at eval (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:4644:28)
      at then (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:186:79)
      at eval (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:4634:20)
      at eval (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:1332:28)
      at safeCall (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:179:25)
      at executeComponent (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:1332:12)
      at renderSSRComponent (file:///home/projects/qwik-starter-2irmfx/server/assets/@qwik-city-plan-00ac1429.js:1591:6)

This can be separate issue in itself.

It is enough to add deno to get a failing build (no need to add prisma).

In my case the problem was with deno and prisma combined, build was failing when i add prisma.

sarat1669 commented 2 months ago

This is happening with prisma and node as well

sarat1669 commented 2 months ago

Adding an alias in vite.config.ts resolved this

    resolve: {
      alias: {
        ".prisma/client/index-browser": "./node_modules/.prisma/client/index-browser.js"
      }
    },
Jolg42 commented 1 month ago

Disclaimer: I did not try this with Deno, yet, but I hope it will help.

Could you try that and let us know if that works for?

I found out that the "Invalid module" error 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.

Originally posted by @Jolg42 in https://github.com/prisma/prisma/issues/21094#issuecomment-2142474474

gioboa commented 2 weeks ago

@krishna-santosh Did you solve the problem?

krishna-santosh commented 2 weeks ago

Tried both solutions proposed by @sarat1669 and @Jolg42, but unfortunately they both didn't work.

vite v5.3.1 building SSR bundle for production...
".prisma/client/index-browser" is imported by ".prisma/client/index-browser?commonjs-external", but could not be resolved – treating it as an external dependency.
βœ“ 44 modules transformed.
server/build/q-C4YPi7sT.css    4.85 kB
server/entry.ssr.js            0.07 kB
server/@qwik-city-plan.js     41.01 kB
server/entry.deno.js          51.10 kB
server/q-BulQp7W4.js          60.24 kB
server/q-BN1iqjfz.js         348.71 kB
βœ“ built in 5.39s
error during build:
TypeError [PLUGIN_ERROR]: Invalid module ".prisma/client/index-browser" is not a valid package name imported from /home/user/Code/Test/qwik-app/server/@qwik-city-plan.js
    at parsePackageName (node:internal/modules/esm/resolve:768:11)
    at packageResolve (node:internal/modules/esm/resolve:792:5)
    at moduleResolve (node:internal/modules/esm/resolve:914:18)
    at defaultResolve (node:internal/modules/esm/resolve:1119:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:541:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:510:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

undefined
gioboa commented 2 weeks ago

Thanks @krishna-santosh In the Prisma docs I found

previewFeatures = ["deno"]

Are you using this configuration?

krishna-santosh commented 2 weeks ago

I added it to schema.prisma and tried building the project again, but the result is still the same.

jkomyno commented 1 day ago

Related issue: https://github.com/prisma/prisma/issues/21094

aarbi commented 23 hours ago

this would be fixed by using deno run's --unstable-sloppy-imports for the .js in the import path, but I am not sure if that can be added to vercel configs.