mermaid-js / mermaid-cli

Command line tool for the Mermaid library
MIT License
2.48k stars 234 forks source link

Syntax error when running mmdc #427

Closed EricBuist closed 1 year ago

EricBuist commented 1 year ago

Describe the bug When trying to run Mermaid CLI, even before rendering anything, I'm getting a syntax error preventing the tool to work at all.

file:///home/eric_buist/workspace/nle/ct-platform-nlu-nle/node_modules/@mermaid-js/mermaid-cli/src/index.js:209
          throw new Error(error?.message ?? 'Unknown mermaid render error')
                                ^

SyntaxError: Unexpected token '.'
    at Loader.moduleStrategy (internal/modules/esm/translators.js:133:18)

To Reproduce Steps to reproduce the behavior:

  1. On Ubuntu 22.04, install NodeJS 12.x using sudo apt install nodejs npm
  2. Install Mermaid CLI using npm install @mermaid-js/mermaid-cli.
  3. Run npx mmdc -h
  4. Observe the error message.

The Mermaid CLI is completely unusable.

Expected behavior A clear and concise description of what you expected to happen.

Mermaid CLI should display a usage screen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

MindaugasLaganeckas commented 1 year ago

Thank you for reporting the problem. Can you tell us which version of mermaid-cli you have installed and gives you the error? The newest version is 9.1.7. Also a docker version of mermaid-cli is available. And it works fine. Another thing, can you attach your mermaid diagram file? We have a test for similar scenario and I cannot see how our test is different from what you try to do.

EricBuist commented 1 year ago

This is version 9.1.7. I didn't select any version explicitly, so I imagine NPM installed the most recent version.

Starting Mermaid CLI fails even before loading any diagram. Running the CLI without arguments or with -h shows the syntax error above.

I just saw the following when I tried to reinstall Mermaid-cli:

npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'puppeteer@18.2.1',
npm WARN EBADENGINE   required: { node: '>=14.1.0' },
npm WARN EBADENGINE   current: { node: 'v12.22.9', npm: '8.5.1' }
npm WARN EBADENGINE }

Could it be that Mermaid only works with NodeJS 14? Is there any documentation about that? I am using Ubuntu 22.04, the most recent LTS, and even that one sticks to NodeJS 12.

aloisklink commented 1 year ago

Could it be that Mermaid only works with NodeJS 14?

Unfortunately, that's the case. Mermaid relies on puppeteer, which dropped support for Node.JS v12 a couple of versions ago (see https://github.com/puppeteer/puppeteer/releases/tag/v14.0.0)

It doesn't help that although npm prints a warning Node.JS is out-of-date, it's very easy to ignore since there are a lot of other warnings.

I am using Ubuntu 22.04, the most recent LTS, and even that one sticks to NodeJS 12.

Node.JS v12 has been end-of-life since 2022-04-30.

If you use the built-in Ubuntu/Debian NodeJS, they're usually running very outdated versions of NodeJS, and they're only officially supported by the OS maintainers, so you're relying on them to backport bug/security fixes, which is often difficult since their versions are so out-of-date.

My recommendation is to install a supported version of Node.JS using the official instructions: https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

Installing via snap is probably the easiest way to get started if you're on Ubuntu, and it should auto-update to the latest version so you don't need to worry about security issues.

aloisklink commented 1 year ago

Is there any documentation about that?

I'll add an badge to the the README.md in #428 that adds node-lts (scoped) to the README.md

Generally in the NPM/JavaScript eco-system, that's enough for people to understand (as well as the warnings/errors when trying to install the package, but it might be worth making it more explicit in the README.md, especially since there might be quite a few people unfamiliar with JavaScript trying to install this package.