question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`new PrismaClient()` can not find `schema.prisma` file when use with pnpm workspace

See original GitHub issue

Bug description

Here is a simple reproduction with pnpm.

- packages
  - server
    - index.mjs #  get PrismaClient from prisma-client
    - package.json 
 
  - prisma-client
    - dist # prisma generator output
    - prisma
      - schema.prisma
    - package.json

  - pnpm-workspace.yaml
  - package.json

When call new PrismaClient in packages/server/index.mjs, got an error:

Error: ENOENT: no such file or directory, open '~/prisma-path-issue/packages/server/node_modules/schema.prisma'
    at Object.openSync (node:fs:585:3)
    at Object.readFileSync (node:fs:453:35)
    at new LibraryEngine (~/prisma-path-issue/packages/prisma-client/dist/runtime/index.js:36041:40)
    at PrismaClient.getEngine (~/prisma-path-issue/packages/prisma-client/dist/runtime/index.js:39247:16)
    at new PrismaClient (~/prisma-path-issue/packages/prisma-client/dist/runtime/index.js:39218:29)
    at getPrisma (file://~/prisma-path-issue/packages/server/index.mjs:4:18)
    at file://~/prisma-path-issue/packages/server/index.mjs:9:1
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '~/prisma-path-issue/packages/server/node_modules/schema.prisma',
  clientVersion: '3.5.0'
}

How to reproduce

(Require global pnpm installed)

  1. Clone git https://github.com/mervinjin/prisma-issue
  2. Run pnpm install
  3. Run pnpm start
  4. See error

Expected behavior

No Error

Prisma information

Schema file:

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}
generator client {
  provider = "prisma-client-js"
  output = "../dist"
}

model User {
  id Int @id @default(autoincrement())
}

Usage:

import { PrismaClient } from 'prisma-client'

async function getPrisma(){
  const prisma = new PrismaClient()
  await prisma.$connect()
  return prisma
}

getPrisma().then(console.log)

Environment & setup

  • OS: Mac OS
  • Database: SQLite
  • Node.js version: 17.0.1

Prisma Version

prisma                  : 3.5.0
@prisma/client          : 3.5.0
Current platform        : darwin
Query Engine (Node-API) : libquery-engine 78a5df6def6943431f4c022e1428dbc3e833cf8e (at ../../node_modules/.pnpm/@prisma+engines@3.5.0-38.78a5df6def6943431f4c022e1428dbc3e833cf8e/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli 78a5df6def6943431f4c022e1428dbc3e833cf8e (at ../../node_modules/.pnpm/@prisma+engines@3.5.0-38.78a5df6def6943431f4c022e1428dbc3e833cf8e/node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core 78a5df6def6943431f4c022e1428dbc3e833cf8e (at ../../node_modules/.pnpm/@prisma+engines@3.5.0-38.78a5df6def6943431f4c022e1428dbc3e833cf8e/node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt 78a5df6def6943431f4c022e1428dbc3e833cf8e (at ../../node_modules/.pnpm/@prisma+engines@3.5.0-38.78a5df6def6943431f4c022e1428dbc3e833cf8e/node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash    : 78a5df6def6943431f4c022e1428dbc3e833cf8e
Studio                  : 0.439.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
janpiocommented, Nov 23, 2021

Shouldn’t the goal be that this just works as intended, without any further need to specify anything?

4reactions
millspcommented, Mar 25, 2022

Hey @plimeor @andyjy I can confirm that this issue has been fixed. I just ran the repro with @prisma/client@dev which works now 😃. If you want, you can also try it, and please let us know if you find anything unexpected. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Prisma with Yarn v3 - Stack Overflow
I've just made a new branch in git and am trying to move my project to use PnP. However, when I run yarn...
Read more >
Prisma - Browse /3.12.0 at SourceForge.net
For more information, see the SourceForge Open Source Mirror Directory. ... new PrismaClient() can not find schema.prisma file when use with pnpm workspace...
Read more >
Using Prisma with Turborepo
Run npx prisma init . This should create several files inside packages/database : prisma/schema.prisma .gitignore ...
Read more >
With the newest version of pnpm 7 2 1 I get an error with th | Prisma
... with the prisma client package name ERR PNPM BAD PACKAGE JSON pnpm workspace ... This is no problem, the folder structure is...
Read more >
Deploying sveltekit app on vercel, problems (fetching ... - Reddit
This is my endpoint code: // /users/index.js import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient(); export const get = ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found