Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Prisma Client removed on adding a new package: Error: @prisma/client did not initialize yet #390

Closed
divyenduz opened this issue Jan 8, 2020 · 63 comments
Assignees
Labels
bug/1-repro-available A reproduction exists and needs to be confirmed. kind/bug A reported bug. tech/typescript Issue for tech TypeScript.
Milestone

Comments

@divyenduz
Copy link

divyenduz commented Jan 8, 2020

This behavior can be observed in both npm and yarn, setup a Photon project and run any query with photon to ensure that it exists.

Now add any dependency in yarn, npm and re-execute photon query. I reproduced this with yarn add dotenv or npm install dotenv.

It doesn't matter if dotenv is already install or is a new package. I could reproduce this reliably.

You would run into (error paraphrased):

npm: import { Photon } from '@prisma/photon' no found.
yarn: Photon is not initialized yet. Please run prisma2 generate again

I used the following versions:

divyendusingh [prisma]$ yarn --version
1.21.1
divyendusingh [prisma]$ npm --version
6.10.2
@divyenduz divyenduz added bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. process/candidate Candidate for next Milestone. labels Jan 8, 2020
@divyenduz divyenduz changed the title Photon removed on adding a new package Photon removed on adding a new package: Error: "Photon is not initialized yet" Jan 9, 2020
@timsuchanek
Copy link
Contributor

I can't reproduce this with npm@6.13.4 and yarn@1.21.1.

@timsuchanek timsuchanek added bug/0-needs-info More information is needed for reproduction. and removed bug/2-confirmed We have confirmed that this is a bug. labels Jan 17, 2020
@divyenduz
Copy link
Author

I could reproduce this once today. But not anymore afterwards. I would love to keep this in the next sprint as I think it is important and try to find a reproduction.

@janpio janpio added this to the Preview 21 milestone Jan 17, 2020
@janpio janpio added bug/1-repro-available A reproduction exists and needs to be confirmed. and removed bug/0-needs-info More information is needed for reproduction. labels Jan 17, 2020
@divyenduz
Copy link
Author

Tim has a reproduction of a different error of similar nature now. I will look for a related reproduction of the actual error "Photon is not initialized yet. Please run prisma2 generate again" but Tim can already start on the other bit of it.

@divyenduz
Copy link
Author

"Photon is not initialized yet. Please run prisma2 generate again" this is also observable on Heroku. Might be related, will create a separate issue, if needed.

@timsuchanek timsuchanek added bug/0-needs-info More information is needed for reproduction. and removed bug/1-repro-available A reproduction exists and needs to be confirmed. labels Jan 20, 2020
@timsuchanek timsuchanek removed their assignment Jan 20, 2020
@timsuchanek
Copy link
Contributor

I created a reproduction attempt in https://github.com/timsuchanek/photonjs-390. But just an attempt. Unassigning myself until we have a reliable reproduction.

@janpio janpio removed the process/candidate Candidate for next Milestone. label Jan 21, 2020
@pantharshit00
Copy link
Contributor

I am also unfortunately unable to reproduce this.

@divyenduz
Copy link
Author

I am also unable to reproduce this with a local package like in Tim's repo. I tried that and its file variant (referring to prisma-client by its folder).

@janpio
Copy link
Member

janpio commented Jan 30, 2020

Note: Update issue title and description to new output.

@Zhomart
Copy link

Zhomart commented Jun 18, 2020

There is prisma/prisma#2106 similar discussion going. I had similar issue, but it was my own fault adding **/node_modules/** to ignore field in firebase.json.

UPDATE: false alarm, use yarn instead of npm. You can still ignore node_modules.

@Jolg42
Copy link
Member

Jolg42 commented Jun 18, 2020

@janpio I created this issue for the Firebase problem #732

@deadcoder0904
Copy link
Contributor

I got this error Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again. when I updated Prisma to v2.2.0

@janpio
Copy link
Member

janpio commented Jul 8, 2020

Can you open a new issue pls @deadcoder0904? Thanks.

@deadcoder0904
Copy link
Contributor

I think I opened in wrong repo 🤦‍♂️ prisma/prisma#2963

@janpio
Copy link
Member

janpio commented Jul 8, 2020

All good. Thanks.

@nargetdev
Copy link

@deadcoder0904 same here - exactly when I upgraded to "@prisma/client": "2.2.0" (which was necessary to fix a different bug within prisma up from 2.1.0)

@deadcoder0904
Copy link
Contributor

@nargetdev did you solve it? if not, here's the solution :)

@MichaelGorski
Copy link

I am getting this error. Couldn't find any workarounds yet.

Bildschirmfoto 2020-09-07 um 12 23 40

My dependencies

  "dependencies": {
    "@prisma/client": "^2.6.2",
    "apollo-server": "^2.17.0",
    "body-parser": "^1.19.0",
    "connect": "^3.7.0",
    "cors": "^2.8.5",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "faker": "^5.1.0",
    "firebase-admin": "^9.1.1",
    "nexus": "^0.26.1",
    "nexus-plugin-prisma": "^0.18.1",
    "uuid": "^8.3.0"
  },
  "devDependencies": {
    "@babel/cli": "^7.11.6",
    "@babel/core": "^7.11.6",
    "@babel/node": "^7.10.5",
    "@babel/preset-env": "^7.11.0",
    "@prisma/cli": "^2.6.2",
    "@types/node": "^14.6.4",
    "cross-env": "^7.0.2",
    "nodemon": "^2.0.4",
    "ts-node": "^9.0.0",
    "ts-node-dev": "^1.0.0-pre.62",
    "typescript": "^4.0.2"
  },

@sreuter
Copy link

sreuter commented Sep 7, 2020

@MichaelGorski You should remove your @prisma/cli and @prisma/client dependencies from your package.json and delete your node_modules (and yarn.lock if you use yarn) and install things fresh again.

That being said, I'm getting the same error right now, even tho I don't have those in my package.json.

@MichaelGorski
Copy link

MichaelGorski commented Sep 7, 2020

Solved it
Somehow when I installed nexus, my dependencies were bugged and it installed @prisma/client as a dependencie like @prisma/cli.

My Solution:
Remove all related dependencies, delete node_modules. Install it clear. Remove all related prisma/nexus files from your project.
Add nexus, run nexus dev. You should get a warning with empty Graphql etc.. Then move all the files back to api/graphql, add nexus-plugin-prisma, run nexus dev and it should work again.

@sreuter Did you try my solution? It worked for me

edit: grammar

@sreuter
Copy link

sreuter commented Sep 7, 2020

Thanks @MichaelGorski.. For me it was something else in case somebody still has problems:

I had to remove output = "./generated/client" from my schema.prisma (which was a left over from using the client directly before nexus), so npx prisma generate actually creates the client in the right location.

@talentlessguy
Copy link

Happens with pnpm 5.6 and node 14.8

 Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again

even though the client is already generated

doesn't work with yarn 1.22.5 either

even tho the client exists:

➜ ls node_modules/@prisma/client
 generator-build   node_modules   runtime
 index.d.ts        package.json   scripts
 index.js          README.md     

@pantharshit00
Copy link
Contributor

@talentlessguy Client is not generated at that location now, please check node_modules/.prisma

@talentlessguy
Copy link

@pantharshit00 there's this:

➜ ls node_modules/.prisma/client
 index.d.ts   index.js   package.json   query-engine-debian-openssl-1.1.x   schema.prisma

@jdevng
Copy link

jdevng commented Nov 1, 2020

My environment is setup with a prisma2 directory and an apollo2 directory. The prisma directory is setup connected to MySQL. Commands invoked from the CLI write and read to/from the database.

I am attempting to load Prisma Client for use in Apollo2. I am in the Apollo directory, and add the dependency for prisma client using the following:

npm install "@prisma/client" --save-dev

I added the following code to my index.js for Apollo:

import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();

I get the following error:

Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.

No idea what this means, I wouldn't assume a dependency would need to be 'initialized', but I assume it's trying to build code from my schema. So I run

% npx prisma generate --schema ../prisma/hello-prisma/prisma/schema.prisma

which points to my prisma schema I had setup previously, I'm assuming this is used to generate the client code. It completes without error.

When invoking apollo, I get the same generate error. So I run the following:

% prisma generate
 ▸    Couldn’t find `prisma.yml` file. Are you in the right directory?

How do I set this up so that Apollo can load in the PrismaClient?

Dependencies:

"devDependencies": {
    "@prisma/cli": "^2.8.0",
    "@types/node": "^14.11.2",
    "ts-node": "^9.0.0",
    "typescript": "^4.0.3"
  },
  "dependencies": {
    "@prisma/client": "^2.8.0"
  }

@Jolg42
Copy link
Member

Jolg42 commented Nov 2, 2020

Hi @jdevng!

Your output here

% prisma generate
 ▸    Couldn’t find `prisma.yml` file. Are you in the right directory?

looks like Prisma 1 output, to avoid this you could run npx like this npx @prisma/cli generate or install it globally npm i -g @prisma/cli

@srikanthkyatham
Copy link

srikanthkyatham commented Nov 24, 2020

Hi @jdevng!

Your output here

% prisma generate
 ▸    Couldn’t find `prisma.yml` file. Are you in the right directory?

looks like Prisma 1 output, to avoid this you could run npx like this npx @prisma/cli generate or install it globally npm i -g @prisma/cli

If the above advise would have mentioned in the output, it would be more helpful.

@Jolg42
Copy link
Member

Jolg42 commented Nov 24, 2020

@srikanthkyatham It's something we want to improve indeed! 😃

@samrith-s
Copy link

Hey. I am trying to deploy my lambda function which used Prisma 2. I was directed to this issue with from the error.

I currently do:

prisma generate

And then package everything.

In my package, I have a node_modules folder. Which has all of the prisma stuff:
image

Is something missing? Coz I get this error when trying to run my lambda:
image

@Jolg42
Copy link
Member

Jolg42 commented Jan 6, 2021

Context for @samrith-s comment's #390 (comment)
Minimal reproduction https://github.com/samrith-s/nestjs-prisma-serverless-error
https://prisma.slack.com/archives/CKQTGR6T0/p1609623950269000

@samrith-s
Copy link

I had a chat with @ryands17 and he advised me to include @prisma/cli to the build. Now my package size rose from 7MB to 59MB! Is there any way to reduce this? Coz this is eating up on my deployment time massively.

@Jolg42
Copy link
Member

Jolg42 commented Jan 7, 2021

@samrith-s in your case you could remove the @prisma/cli and generate the Prisma Client in a custom folder that you include when doing the deployment.
See https://www.prisma.io/docs/concepts/components/prisma-client/generating-prisma-client#specifying-a-custom-output-path
Does that work for you?

@samrith-s
Copy link

@Jolg42 yeah I tried that. But I still need to manually pack the rhel-open-ssl binary with lambda which isn't done at all in the example.

I have so much boilerplate code just to make the query engine available to Prisma, have no idea how it works in the SLS Lambda example here: https://www.prisma.io/docs/guides/deployment/deploying-to-aws-lambda

@Jolg42
Copy link
Member

Jolg42 commented Jan 11, 2021

@samrith-s Could you maybe create a new issue about that with your boilerplate code?

@NickSchmitt
Copy link

NickSchmitt commented Jan 13, 2021

Once I get to npm run dev at the beginning of the Prisma Quick Start Tutorial, I receive an error that tells me to report here:

Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma-client-js/issues/390.

Upon running prisma generate I receive zsh: command not found: prisma

@Jolg42
Copy link
Member

Jolg42 commented Jan 13, 2021

Note: discussion from previous comment is there prisma/prisma#4978

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/1-repro-available A reproduction exists and needs to be confirmed. kind/bug A reported bug. tech/typescript Issue for tech TypeScript.
Projects
None yet
Development

No branches or pull requests