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

Module "@prisma/client" has no exported member "PrismaClient" #13946

Closed
SooditK opened this issue Jun 21, 2022 · 18 comments · Fixed by prisma/language-tools#1424
Closed

Module "@prisma/client" has no exported member "PrismaClient" #13946

SooditK opened this issue Jun 21, 2022 · 18 comments · Fixed by prisma/language-tools#1424
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: pnpm
Milestone

Comments

@SooditK
Copy link

SooditK commented Jun 21, 2022

Bug description

image

The latest version of @prisma/client (3.15.2) has (In my opinion) made some changes, and PrismaClient is no longer being exported from "@prisma/client";

How to reproduce

  1. Go to the file, where you want to import & import { PrismaClient } from "@prisma/client"
  2. See error

Expected behavior

No response

Prisma information

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["referentialIntegrity"]
}

datasource db {
  provider             = "mysql"
  url                  = env("DATABASE_URL")
  referentialIntegrity = "prisma"
}

model user {
  id             Int      @id @default(autoincrement())
  email          String   @unique
  First_Name     String   @map("First Name")
  Last_Name      String   @map("Last Name")
  Password       String
  created_at     DateTime @default(now())
  updated_at     DateTime
}

Environment & setup

  • OS: EndeavourOS Linux x86_64 (Arch Linux)
  • Database: MySQL (Provisioned by PlanetScale)
  • Node.js version: 18.3.0

Prisma Version

3.15.2
@SooditK SooditK added the kind/bug A reported bug. label Jun 21, 2022
@arthurfiorette
Copy link
Contributor

did you ran prisma generate as the docs says?

@matthewmueller matthewmueller added the team/client Issue for team Client. label Jun 21, 2022
@matthewmueller
Copy link
Contributor

matthewmueller commented Jun 21, 2022

As @arthurfiorette mentioned, I think you're missing a prisma generate. Perhaps you cloned the repo?

@matthewmueller matthewmueller added the bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. label Jun 21, 2022
@SooditK
Copy link
Author

SooditK commented Jun 22, 2022

As @arthurfiorette mentioned, I think you're missing a prisma generate. Perhaps you cloned the repo?

I won't raise an Issue, without running the prisma generate command sir. I've done a prisma db push as well.
Restarted my TypeScript Server. And the weird thing here is, the Package Manager.

pnpm is giving this error, But If I delete the node_modules/ and re-install all the dependencies with npm It works fine.

In most of my Projects, I use pnpm and all of them when ran pnpm install gives the same error.

@thasmo
Copy link

thasmo commented Jul 22, 2022

Installing via pnpm and using import { PrismaClient } from '@prisma/client'; the typescript server states:

Cannot resolve symbol 'PrismaClient'

I've run pnpx prisma generate which created node_modules/.prisma/client; still it's not picked up for some reason.

@pgiovanni
Copy link

I'm having the same issue on endeavourOS. I've run prisma generate and tried to reinstall node_modules as well.

@SooditK
Copy link
Author

SooditK commented Jul 28, 2022

I'm having the same issue on endeavourOS. I've run prisma generate and tried to reinstall node_modules as well.

Installing via pnpm and using import { PrismaClient } from '@prisma/client'; the typescript server states:

Cannot resolve symbol 'PrismaClient'

I've run pnpx prisma generate which created node_modules/.prisma/client; still it's not picked up for some reason.

I dont't know if it's the Operating System or the Package Manager, I've to use npm instead of pnpm everytime I use Prisma. With a TSServer Restart, It does the work.

@pgiovanni
Copy link

pgiovanni commented Jul 29, 2022

Try updating prisma. There apparently was a new major version update. Version 4.1 now.

@tjmgregory
Copy link

tjmgregory commented Aug 3, 2022

Also facing the exact same issue with pnpm and prisma. The node_modules/.prisma dependency is generated correctly, but what's happening is @prisma/client points to node_modules/.pnpm/@prisma+client@3.15.2_prisma@3.15.2/node_modules/@prisma/client/index.d.ts - so the nested dependency approach of pnpm to avoid version conflicts is getting in the way.

Edit: Was using pnpm 7.5.2, upgrading to pnpm 7.8.0, deleting node_modules and running PRISMA_SKIP_POSTINSTALL_GENERATE=true p install fixed it for me. Which of those steps did the trick though 🤷

@SooditK
Copy link
Author

SooditK commented Aug 3, 2022

Also facing the exact same issue with pnpm and prisma. The node_modules/.prisma dependency is generated correctly, but what's happening is @prisma/client points to node_modules/.pnpm/@prisma+client@3.15.2_prisma@3.15.2/node_modules/@prisma/client/index.d.ts - so the nested dependency approach of pnpm to avoid version conflicts is getting in the way.

Edit: Was using pnpm 7.5.2, upgrading to pnpm 7.8.0, deleting node_modules and running PRISMA_SKIP_POSTINSTALL_GENERATE=true p install fixed it for me. Which of those steps did the trick though shrug

As you mentioned, Sir, I updated pnpm to 7.8.0 and deleted the node_modules
ran, PRISMA_SKIP_POSTINSTALL_GENERATE=true pnpm install
This thing didn't worked for me.
I created a new project to test this out, But still the same issue occurred.

@thasmo
Copy link

thasmo commented Aug 4, 2022

Edit: Was using pnpm 7.5.2, upgrading to pnpm 7.8.0, deleting node_modules and running PRISMA_SKIP_POSTINSTALL_GENERATE=true p install fixed it for me. Which of those steps did the trick though 🤷

Did not fix it for me either.

I've also set this in the project's .npmrc file:

node-linker=hoisted
symlink=false
package-import-method=copy

But even that didn't help.

@millsp millsp self-assigned this Sep 13, 2022
@millsp millsp added the tech/typescript Issue for tech TypeScript. label Sep 13, 2022
@millsp millsp removed their assignment Sep 13, 2022
@irg1008
Copy link

irg1008 commented Feb 2, 2023

So, do we know something about this? Still happening, I don't have any types for prisma client. It works when exporting the client from the package base directory. Stops working when exporting from src. I am starting to wonder what the point of pnpm is really

@millsp
Copy link
Member

millsp commented Feb 2, 2023

Hey @irg1008, could you provide us with a simple reproduction?

@irg1008
Copy link

irg1008 commented Feb 3, 2023

Sure,

I have a pnpm monorepo with turborepo.
My prisma schema output is in a "database" package:

Custom client output:

generator client {
  provider = "prisma-client-js"
  output   = "../node_modules/.prisma/client" // We need to export the client to the root for production and to pnpm virtual store for development
}

So when I disable the custom output, the prisma client is built out to the .pnpm virtual store, and as so it works on both dev and prod in apps "database" is dependency of.

The issue is that when doing this, I am missing typing on dev. This happens because the TS server links to the package "database" (without generated prisma client) even when it actually is importing it from the virtual store.

Project tree:

  • node_modules (root)
    • .pnpm
      • .prisma

      (default prisma client output). (Works when exporting here, no typing)

  • apps
    • server (links types to database, consumes from virtual store)
  • packages
    • database
      • node_modules (exporting here adds typings but prod fails)
      • prisma/schema

The solution to have both the correct build link and typing it's to generate the clients in both places.

This causes and immediate problem when updating the schema.You have to generate the client two times, etc etc

We can solve this if we automatically output the schema to both node_modules (root and package).

Or maybe I am missing some settings with pnpm.

Any help would be great!

@irg1008
Copy link

irg1008 commented Feb 3, 2023

A basic fix is to point prisma client output to root node_modules like:

generator client {
  provider = "prisma-client-js"
  output   = "../../../node_modules/.prisma/client" // Root of the monorepo
}

This works when building and in dev mode.

I see problems with this approach while deploying the app as a separate project and not as a monorepo; schema would point to a non existant folder

Additional info (.pnpm):

auto-install-peers = true
enable-pre-post-scripts=true
public-hoist-pattern[]=*prisma*

@ARMATAV
Copy link

ARMATAV commented May 3, 2023

Same issue here - it's searching for it in the wrong location

@millsp
Copy link
Member

millsp commented May 22, 2023

@ARMATAV @irg1008 @SooditK @pgiovanni @thasmo

Are you by any chance using preserveSymlinks?
I confirmed that this is causing issues with Prisma Client and pnpm, setting it to false prevents type issues.

Have you tried to restart VSCode or the TS Server?
Some users have reported that after being generate, VSCode did not pick up the new generated types.

There are many issues interleaved, and so far we know my two mentions just above are things we need to fix.

Did any of these help? If not, could you please provide us with a small reproduction? We are not able to reproduce the issues mentioned in the comments, so we need your help 🙏 I'd appreciate if you could submit us some code.

@fdj0429
Copy link

fdj0429 commented Mar 28, 2024

This is how install works for me on Win10:

set NODE_OPTIONS="--preserve-symlinks"
pnpm install // will emit error, no worry continue with next step
cd packages/hoppscotch-backend
rm -rf dist && pnpm prisma generate && pnpm install
cd -
pnpm install

@Chandraprakash-Darji
Copy link

A basic fix is to point prisma client output to root node_modules like:

generator client {
  provider = "prisma-client-js"
  output   = "../../../node_modules/.prisma/client" // Root of the monorepo
}

This works when building and in dev mode.

I see problems with this approach while deploying the app as a separate project and not as a monorepo; schema would point to a non existant folder

Additional info (.pnpm):

auto-install-peers = true
enable-pre-post-scripts=true
public-hoist-pattern[]=*prisma*

It's been one year have you got the solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: pnpm
Projects
None yet
Development

Successfully merging a pull request may close this issue.