Importing @prisma/client takes 6s (includes repro and which line causes it)
See original GitHub issueBug 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
- Clone this repo: https://github.com/flesler/prisma-boot-test
npm install
npm run build
npm start
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:
- Created 2 years ago
- Reactions:5
- Comments:12 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 thatprocess.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:
Windows PC:
(Both machines run Node.js 17.0.1)
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.