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

Fails to find mmdc binary in Yarn 2 with Plug'n'Play #104

Closed zkulbeda closed 1 year ago

zkulbeda commented 2 years ago

Example repo Error:

Error: Command failed: find ../.. -name mmdc

or another error:

Error: Expected mermaid CLI at
C:\Users\user\Project\prisma\node_modules\.bin\mmdc

or
undefined
 but this package was not found.
keonik commented 2 years ago

This is the most common problem we keep running into. node_module mapping to successfully call a CLI for Mermaid. Happy to review PR's related to a fix. It seems all that have been merged have fixed for one case and failed for the next. In the meantime, to generate in a format that will skip the CLI failure you could generate to markdown

generator erd {
  provider = "prisma-erd-generator"
  output   = "./dist/erd.md"
}

I just tried it out and it generated successfully which tells me its not a formatting issue for the CLI, just a path issue

zkulbeda commented 2 years ago

It really worked! Thank you.

keonik commented 2 years ago

No problem! Glad that will work for you. I want to say one of the best solutions to this problem is to add a variable to the node_module path so we can set it case by case. It will cause some breaking changes for many though. Leaving open to track that

Markkos89 commented 2 years ago

Hi @keonik , such a great generator, thanks and congrats.

Just for letting you know, running on a WSL2 ubuntu 22 distro, with the --data-proxy flag, the generator fails.. also added the output as you suggested here previously. The ouput is:

image

workaround to it by creating an empty erd.md file in the output path.

Now my question is, and sorry for this but I ignore the answer, how can I "visualize" this .md file?? For example, with the .png file I was to add it to the README.md file, and see the updated image there... any suggestion?

Best regards and thanks again!

zkulbeda commented 2 years ago

Hi @Markkos89, Github has build-in support for rendering mermaid language syntax. Just push .md file into github repo and check it out. On the other hand, you can render mermaid code manually on https://mermaid.live/edit

Markkos89 commented 2 years ago

Hi @Markkos89, Github has build-in support for rendering mermaid language syntax. Just push .md file into github repo and check it out. On the other hand, you can render mermaid code manually on https://mermaid.live/edit

yep, that worked for now, thanks !!! The thing is I wanted to include my ERD Diagram in my README.md file, to have more exposure at first sight or something.... couldn't do it so far...

also the mermaid.live/edit doesnt show my diagram, it tells me syntax error :(

dont worry about the live editor, doesn't matter for me right now, but if you know how to see the erd.md diagram in the README.md file I will appreacite the suggestion ;)

for now I have it in another file and is showing. thanks again

keonik commented 2 years ago

I believe all that is in the generated mermaid markdown file is something like this

"""mermaid
// syntax to render ERD in markdown
"""

So if you copied the contents out of that generated markdown file and into your README.md wherever you want to put it, it should render for you.

That then leaves you manually updating your README.md any time your ERD changes. You could script that out and automate it but the easier would be to just link your README.md to your generated ERD.md

keonik commented 1 year ago

Added another option to specify the path to the binary for mmdc in #188

Although markdown is a workaround to generate successfully, this will let you find the path to the binary so that wherever it does exist it won't throw the package not found error anymore. Let me know if you run into issues