prisma / prisma-client-js

Type-safe database client for TypeScript & Node.js (ORM replacement)
Apache License 2.0
1.47k stars 67 forks source link

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

Closed divyenduz closed 4 years ago

divyenduz commented 4 years ago

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
talentlessguy commented 4 years ago

@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 commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

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

samrith-s commented 3 years ago

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 commented 3 years ago

Context for @samrith-s comment's https://github.com/prisma/prisma-client-js/issues/390#issuecomment-753529630 Minimal reproduction https://github.com/samrith-s/nestjs-prisma-serverless-error https://prisma.slack.com/archives/CKQTGR6T0/p1609623950269000

samrith-s commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

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

NickSchmitt commented 3 years ago

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 commented 3 years ago

Note: discussion from previous comment is there https://github.com/prisma/prisma/discussions/4978