mermaid-js / mermaid-cli

Command line tool for the Mermaid library
MIT License
2.31k stars 223 forks source link

Crashes immediately with a SyntaxError on WSL #576

Closed rhyswilkins closed 1 year ago

rhyswilkins commented 1 year ago

I installed using a local installation as follows: % npm install @mermaid-js/mermaid-cli which seemed to complete OK. I then added /home/rhys/node_modules/.bin to PATH, as that's where the mmdc command ended up.

Then I run it as follows % mmdc -h

I expected to see the help information for the mmdc command. Instead, I get a crash, per the screenshot: mmdc-crash-wsl

This is on WSL. I'm using Windows 10, and Ubuntu 22.04.2 LTS.

I've tried also asking it to generate a diagram, and that's the same.

Yokozuna59 commented 1 year ago

duplicate of #232

aloisklink commented 1 year ago

duplicate of https://github.com/mermaid-js/mermaid-cli/issues/232

Correction: this is actually a duplicate of https://github.com/mermaid-js/mermaid-cli/issues/572

@mermaid-js/mermaid-cli has a minimum required Node.JS version of https://github.com/mermaid-js/mermaid-cli/blob/db01c0005514bbd0267344c418f9649faf49a5fd/package.json#L13

(there should have been a warning by NPM when you installed it).

I'd recommend installing a newer version of Node.JS. If you're running Ubuntu, snap or the NodeSource apt repo are generally what I'd recommend using to install Node.JS, so that you'll get automatic updates! The default node that is in the Ubuntu repos is extremely outdated and security fixes are done "best effort" by the Ubuntu team, so it's not as good as the official Node.JS releases.

rhyswilkins commented 1 year ago

Yeah, that fixed it. I had Node v12. I uninstalled that, added the NodeSourc apt repo as described above, and reinstalled Node. I then had to upgrade npm. After that, I ripped out the old config, and re-installed the mermaid package. That pulled in all of the deps and everything, and it works now. Thank you.

aloisklink commented 1 year ago

Awesome to hear!

By the way, there is a engine-strict configuration flag in NPM that will prevent installing packages that aren't compatible with the current Node.JS version. Honestly, I don't know why it's not the default value :shrug:, especially since Node.JS is a language that creates a new major release every 6 months, and even the LTS versions of Node.JS only last for about 2.5 years.