hi all. thank you for this channel. my company lov...
# orm-help
n
hi all. thank you for this channel. my company loves Prisma. i am having trouble using custom client output in a monorepo with NPM 7 workspaces, which hoists all packages to a root
node_modules
. i am having 2 strange issues. any help with either one would be amazing, i suspect they are related. i apologize for the wall of text, it's mostly debug output!!! a quick tour of the monorepo:
Copy code
rpphub/node_modules/@prisma
rpphub/package.json

db workspace source (the prisma project):
rpphub/workspaces/db/package.json
rpphub/workspaces/db/schema.prisma
rpphub/workspaces/db/migrations/*
rpphub/workspaces/db/lib (client output goes here)
rpphub/workspaces/db/lib/index.js
rpphub/workspaces/db/lib/schema.prisma
rpphub/workspaces/db/lib/[...the rest of the generated files..]

and finally a nextjs app trying to utilize prisma client:
rpphub/workspaces/web
furthermore, my
rpphub/workspaces/db/package.json
contains inclusion directives:
Copy code
"main": "lib/index.js",
"browser": "lib/index-browser.js",
"types": "lib/index.d.ts"
***issue 1***: the client does not work from the node REPL for certain working directories. if i am in the
rpphub/workspaces/db
directory i can have the following session:
Copy code
$:~/Code/rpphub/workspaces/db$ node
Welcome to Node.js v14.15.4.
Type ".help" for more information.
> const plib = require('.')
undefined
> const client = new plib.PrismaClient()
undefined
but if i am in the
rpphub
directory, a similar session fails:
Copy code
$:~/Code/rpphub$ node
Welcome to Node.js v14.15.4.
Type ".help" for more information.
> const plib = require('./workspaces/db')
undefined
> const client = new plib.PrismaClient()
Uncaught:
Error: ENOENT: no such file or directory, open '/home/nic/Code/rpphub/.git/schema.prisma'
    at Object.openSync (fs.js:476:3)
    at Object.readFileSync (fs.js:377:35)
    at new LibraryEngine (/home/nic/Code/rpphub/workspaces/db/lib/runtime/index.js:36078:40)
    at PrismaClient.getEngine (/home/nic/Code/rpphub/workspaces/db/lib/runtime/index.js:39108:16)
    at new PrismaClient (/home/nic/Code/rpphub/workspaces/db/lib/runtime/index.js:39079:29) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/home/nic/Code/rpphub/.git/schema.prisma',
  clientVersion: '3.3.0'
}
***issue 2***: the code fails runtime when being included in my Nextjs project in
rpphub/workspaces/web
. at runtime,
import * as PrismaClient from "@rpphub/db";
results in
Copy code
error - Error: Cannot find module 'os'
    at webpackEmptyContext (/home/nic/Code/rpphub/workspaces/web/.next/server/pages/api/test.js:53:10)
    at ../../node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js (webpack-internal:///../db/lib/runtime/index.js:1738:15)
    at __require2 (webpack-internal:///../db/lib/runtime/index.js:87:45)
    at ../../node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/index.js (webpack-internal:///../db/lib/runtime/index.js:2002:56)
    at __require2 (webpack-internal:///../db/lib/runtime/index.js:87:45)
    at eval (webpack-internal:///../db/lib/runtime/index.js:30776:33)
    at Object.../db/lib/runtime/index.js (/home/nic/Code/rpphub/workspaces/web/.next/server/pages/api/test.js:42:1)
    at __webpack_require__ (/home/nic/Code/rpphub/workspaces/web/.next/server/webpack-runtime.js:33:42)
    at eval (webpack-internal:///../db/lib/index.js:17:5)
    at Object.../db/lib/index.js (/home/nic/Code/rpphub/workspaces/web/.next/server/pages/api/test.js:32:1) {
  code: 'MODULE_NOT_FOUND'
which you can see stems from
var os2 = __require("os");
in
rpphub/workspaces/db/lib/runtime/index.js.
. i recognize this could definitely be more of a next-question than a prisma question, if that's the case i apologize! i thought next might require further module transpilation but i had no luck going that route. thank you all!
j
Check the Prisma GitHub issues for details about monorepos. Some scenarios have resolutions and some do not yet. (I would offer more detail but I’m away from the keyboard right now.)
n
thank you, no worries! i looked a bit last night. i found some prs/reverts that were related but couldn't quite make sense of the current state. i will look again with fresh eyes. i hope the monorepo isn't a red herring but it's my primary suspect 🙂 the first issue is weird, just because the client is looking in random places (like .git) for the schema file and ignoring the ones it builds. i will let u know if i have any luck thank u