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.

Importing @prisma/client takes 6s (includes repro and which line causes it)

See original GitHub issue

Bug description

I first asked via Slack here: https://prisma.slack.com/archives/CA491RJH0/p1625770401309600

This exact line takes 6s in my project: import { PrismaClient } from '@prisma/client'

How to reproduce

For me, it takes 4.5s (as shown in the log) even though all it does is import Prisma.

I timed different bits of the generated JS code in .prisma/client until I found the culprit here:

const dirname = findSync(process.cwd(), [
  '"node_modules/.prisma/client"',
  '".prisma/client"',
], ['d'], ['d'], 1)[0] || __dirname

Expected behavior

Import time should be just some milliseconds

Prisma information

The schema from your starter already reproduces it (as shown in the link above)

Environment & setup

  • OS: Ubuntu 20
  • Database: any, happens with PostgreSQL 10 and SQLite
  • Node.js version: 14.17.0

Prisma Version

$ ./node_modules/.bin/prisma -v
Environment variables loaded from .env
prisma               : 2.26.0
@prisma/client       : 2.26.0
Current platform     : debian-openssl-1.1.x
Query Engine         : query-engine 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine     : migration-engine-cli 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary        : prisma-fmt 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : 9b816b3aa13cc270074f172f30d6eda8a8ce867d
Studio               : 0.408.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
aqrlncommented, Oct 26, 2021

As far as I can see, this has been fixed in https://github.com/prisma/prisma/pull/9295 (see https://github.com/prisma/prisma/issues/8484#issuecomment-948995524).

To be safe, I cloned the reproduction repo and ran it on two different machines, both with the version in package.json and the latest 3.3.0. I don’t have a machine with slower disk access handy, but the difference is still noticeable (especially given that process.uptime() that the repro uses measures much more than just importing Prisma, and a significant portion of those 0.1s is Node.js itself booting, so the ratio would be even more significant if those things were subtracted).

Apple M1 Mac:

Prisma version Time
2.26.0 0.4 s
3.3.0 0.1 s (~4x faster)

Windows PC:

Prisma version Time
2.26.0 1.7 s
3.3.0 0.2 s (~8.5x faster)

(Both machines run Node.js 17.0.1)

7reactions
janpiocommented, Sep 17, 2021

This is actively being worked on now. No promises it will make the next release (next week), but expect us to definitely look into this and see how/if/when we can fix this. Thanks for giving us more feedback here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced type safety (Reference) - Prisma
Prisma Client provides full type safety for queries, even for partial queries or included relations. This page explains how to leverage the generated...
Read more >
Go to declaration/auto-import doesn't work in certain situations
Repro 1: Pull down https://github.com/graphql-nexus/examples. Open `plugin-prisma` package and install it's deps via npm or yarn.
Read more >
Error importing PrismaClient in code compiled from typescript ...
The requested module '@prisma/client' is a CommonJS module, which may not support all module.exports as named exports.
Read more >
Next.js template with GraphQL, Urql, Prisma, Nexus and ...
Prisma schema gets regenerated after every yarn/npm add or install. Deployment. Hosting. Recommended hosting choice is Vercel, which works well ...
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