keonik / prisma-erd-generator

Generate an ER Diagram based on your Prisma schema every time you run npx prisma generate
https://www.npmjs.com/package/prisma-erd-generator
MIT License
894 stars 52 forks source link

Unable to generate erd #187

Closed umarfchy closed 1 year ago

umarfchy commented 1 year ago

Hi, I'm trying to generate erd using prisma but getting the following error,

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Error: 
✔ Generated Prisma Client (4.11.0 | library) to ./node_modules/.pnpm/@prisma+client@4.11.0_prisma@4.11.0/node_modules/@prisma/client in 673ms

could not parse datamodel

The prisma client was generated which suggested that the schema is valid. I've also tested the validity using npx prisma validate .

Following are the dependencies.

OS: Debian GNU/Linux 11 (bullseye)
node: v19.8.1

# packages
 "@prisma/client": "^4.9.0",
 "prisma": "^4.9.0",
 "prisma-erd-generator": "^1.3.1",
 "@mermaid-js/mermaid-cli": "^10.0.2",

The prisma schema is as follows:


// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
    provider = "prisma-client-js"
}

generator erd {
    provider                  = "prisma-erd-generator"
    output                    = "./ERD.svg"
    includeRelationFromFields = true
    erdDebug                  = true
}

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

model User {
  id            String         @id
  email         String
  favoriteProducts  FavoriteProducts[]
}

model Product {
  id              String        @id
  title           String
  inFavorites  FavoriteProducts[]
}

model FavoriteProducts {
  userId      String
  user        User    @relation(fields: [userId], references: [id])
  productId   String
  product     Product @relation(fields: [productId], references: [id])

  @@id([userId, productId])
}

I'd really appreciate if someone can help me out :slightly_smiling_face: .

umarfchy commented 1 year ago

I was able to solve the issue by changing the directory that does not contain any spaces in its name. After seeing this issue I suspected that this may be the case. Hope this is fixed in the future.