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

Prisma 3.9.x+ multiple clients being generated, and in the wrong Yarn 1 workspace #12083

Closed
dac09 opened this issue Mar 1, 2022 · 6 comments · Fixed by #12427
Closed

Prisma 3.9.x+ multiple clients being generated, and in the wrong Yarn 1 workspace #12083

dac09 opened this issue Mar 1, 2022 · 6 comments · Fixed by #12427
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/regression A reported bug in functionality that used to work before. topic: yarn workspaces
Milestone

Comments

@dac09
Copy link

dac09 commented Mar 1, 2022

Bug description

In yarn 1 workspaces, sometimes prisma will create the .prisma folder at one or more of the nested workspaces' node_modules.

Migrations and generation produces the client in the root node_modules/.prisma but when running inside a workspace, it picks a different prisma client, causing this error

In our case:

├── node_modules
│   ├── .prisma # 👈 this is good!
├── web
│   ├── node_modules
├── api
│   ├── node_modules
│   │   ├── .prisma  # 😨 whai?

Node version: v16.13.1
Yarn version: 1.23.0-20220130.1630 (set using yarn version classic)

How to reproduce

Reproduction is in this repo here:

Steps to reproduce:

  1. Check that theres no prisma folder in api/node_modules
ls -la api/node_modules
  1. Go into api and generate prisma client
cd api && yarn rw prisma generate
  1. Notice that prisma has now been generated in api node_modules
❯ ls -a api/node_modules
.       ..      .prisma
  1. And to see the actual problem this causes run:
yarn rw prisma migrate dev
# equivalent to
# yarn prisma migrate dev --schema "./api/db/schema.prisma"

and then

yarn rw prisma db seed

And you should see:

PrismaClientKnownRequestError:
Invalid `db.post.create()` invocation in
/Users/dac09/Experiments/prisma-repro/scripts/seed.ts:24:41

  21
  22 Promise.all(
  23   posts.map(async (post) => {
→ 24     const newPost = await db.post.create(
  The table `main.Post` does not exist in the current database.
    at Object.request (/Users/dac09/Experiments/prisma-repro/node_modules/@prisma/client/runtime/index.js:39809:15)
    at PrismaClient._request (/Users/dac09/Experiments/prisma-repro/node_modules/@prisma/client/runtime/index.js:40637:18)
    at /Users/dac09/Experiments/prisma-repro/scripts/seed.ts:24:27
    at async Promise.all (index 0) {
  code: 'P2021',
  clientVersion: '3.10.0',
  meta: { table: 'main.Post' }

Expected behavior

Prisma should only generate client at root of the workspace, not in nested workspaces.

Prisma information

Schema: https://github.com/dac09/prisma-multiple-clients-repro/blob/main/api/db/schema.prisma
Query: https://github.com/dac09/prisma-multiple-clients-repro/blob/main/api/src/services/posts/posts.ts#L6

Environment & setup

  • OS: MacOS, Linux, Windows
  • Database: Tested with SQLite, but likely problem with all DBs
  • Node.js version: 16.13.1

Prisma Version

prisma                  : 3.10.0
@prisma/client          : 3.10.0
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Default Engines Hash    : 73e60b76d394f8d37d8ebd1f8918c79029f0db86
Studio                  : 0.458.0

Mirrored Redwood Issue

redwoodjs/redwood#4605

@dac09 dac09 added the kind/bug A reported bug. label Mar 1, 2022
@janpio janpio added domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. topic: yarn workspaces bug/2-confirmed Bug has been reproduced and confirmed. labels Mar 1, 2022
@janpio
Copy link
Contributor

janpio commented Mar 1, 2022

I can confirm the behavior that @dac09 describes here, I tried it via his Gitpod reproduction before.

@dac09
Copy link
Author

dac09 commented Mar 1, 2022

Confirming that this also happens on Prisma v3.9.2

@dac09
Copy link
Author

dac09 commented Mar 1, 2022

Last known working version (in Redwood world) - Prisma 3.8.1

@millsp hope this helps! ✌️

@dac09 dac09 changed the title Prisma 3.10.0 client being generated in the wrong Yarn 1 workspace Prisma 3.9.x+ multiple clients being generated, and in the wrong Yarn 1 workspace Mar 1, 2022
@janpio janpio added kind/regression A reported bug in functionality that used to work before. and removed kind/bug A reported bug. labels Mar 1, 2022
@thedavidprice
Copy link

Hi @janpio Just checking in here as this little 🐛 keeps popping up for devs. Anything else we could help with at this point?

@millsp
Copy link
Member

millsp commented Mar 11, 2022

Hey @thedavidprice we will work on this coming sprint (starting on 15/03), at this stage everything looks clear to me. Thanks for taking the time doing the investigation @dac09! I'll make sure to add an E2E test for Yarn 1 + Workspaces to avoid any regression in the future.

@thedavidprice
Copy link

@millsp Thank you so much! So you have transparency with our timeline, we are targeting March 21 for a "final" v1-rc, with stable v1 to follow within a couple of weeks. This is one of the last remaining issues on my radar — not meant to imply pressure but just so you know why I'm watching it more closely 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/regression A reported bug in functionality that used to work before. topic: yarn workspaces
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants