"'node_modules/@prisma/client' has no exported member 'PrismaClient'." when using symlinks
Problem
error TS2305: Module '"../../node_modules/@prisma/client"' has no exported member 'PrismaClient'. import { PrismaClient } from '@prisma/client'; How to reproduce create a schema e.g. [code block] 1. Change DB name in prisma.schema to `dev-database.db` 2. `npm run prisma:migrate` 3. `npm run prisma;generate` all of these command are there in package.json script [code block] It was still referring to old database name. and I am not able to run any queries from code. I manually deleted node_modules/.prisma directory. again followed steps 2 and 3 Now I started seeing this problem: `error TS2305: Module '"../../node_modules/@prisma/client"' has no exported member 'PrismaClient'. import { PrismaClient } from '@prisma/client';` I checked the @prisma/client, .prisma directories present inside node_modules Expected behaviour 1.) after `prisma generate` new changes should automatically reflect in prisma client 2.) Should be able to import and use prisma client. Prisma information Environment & setup - OS: Debian Ubuntu 20.04 LTS - Database: SQLite - Prisma version: @prisma/cli : 2.0.0-beta.6 Current platform : debian-openssl-1.1.x - Node.js version: v14.2.0
Error Output
error TS2305: Module '"../../node_modules/@prisma/client"' has no exported member 'PrismaClient'.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix TypeScript Import Error for PrismaClient in Symlinked Node Modules
The error occurs because the TypeScript compiler cannot find the exported member 'PrismaClient' from the '@prisma/client' module due to stale or incorrect generated files in the symlinked node_modules directory. This can happen if the Prisma Client is not properly generated after changes to the schema or if the symlinked path does not resolve correctly.
Awaiting Verification
Be the first to verify this fix
- 1
Verify Prisma Client Generation
Ensure that the Prisma Client is generated correctly after making changes to the schema. Run the following command to regenerate the client.
bashnpx prisma generate - 2
Check for Old Generated Files
Manually check the node_modules/@prisma/client directory for any old or stale files. If they exist, delete the @prisma/client directory to force a fresh generation.
bashrm -rf node_modules/@prisma/client - 3
Reinstall Node Modules
Reinstall the node modules to ensure all dependencies are correctly linked and up to date. This can help resolve issues with symlinks.
bashnpm install - 4
Run Prisma Migrate and Generate Again
After reinstalling, run the migration and generation commands again to ensure that the database schema is up to date and the Prisma Client is generated correctly.
bashnpm run prisma:migrate && npm run prisma:generate - 5
Check TypeScript Configuration
Ensure that your TypeScript configuration (tsconfig.json) includes the correct paths and settings to resolve modules properly. Check for 'baseUrl' and 'paths' settings.
json{ "compilerOptions": { "baseUrl": "./", "paths": { "@prisma/client": ["node_modules/@prisma/client"] } } }
Validation
To confirm the fix worked, run your TypeScript compiler (tsc) and ensure there are no errors related to the import of 'PrismaClient'. Additionally, try executing a simple query using Prisma Client to verify functionality.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep