0

I am attempting to set up a Node.js Express application using Prisma ORM v7.0.1 and a MongoDB database. I keep running into an Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again. whenever I run npm run dev.

The issue persists even after making several adjustments to my configuration files and schema.

What I have tried

  1. Fixed schema.prisma syntax: I corrected a missing double quote in the @map("_id") attribute that was causing prisma generate to fail initially.

  2. Moved Database URL: I moved the url from schema.prisma to my prisma.config.ts file as required by Prisma v7.

  3. Rerunning prisma generate: I have run npx prisma generate multiple times after these changes. The command now runs without validation errors and successfully writes files, but the application error persists.

  4. Noticed generated files are TypeScript: The client files are being generated in the specified output directory as TypeScript files (e.g., .ts), while my application entry point is a .js file using ES Modules.

It seems my prisma generate is now working, but Node/Nodemon still can't initialize the client when running the application.

How do I correctly import the generated Prisma Client given my custom output path and the fact that my source code is JavaScript while the generated files are TypeScript?

My schema.prisma

I have a custom output path for the generated client, and I've tried to fix the MongoDB url issue related to Prisma 7 changes.

generator client {
  provider = "prisma-client"
  output   = "../generated/prisma"
}

datasource db {
  provider = "mongodb"
  // url = env("DATABASE_URL") // Removed this line due to v7 changes
}

model Region {
  id String @id @default(auto()) @map("_id") @db.ObjectId // Corrected the syntax error "_id)"
  name String @unique
  // ... other fields
}

My index.js (using ESM imports)

My main application file is index.js, and I am using import statements.

import e from "express";
import { config } from "dotenv";
import { PrismaClient } from "@prisma/client/extension"; // This is the line where the error points

config()
const prisma = new PrismaClient()
// ... rest of express app set

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.