mermaid-js / mermaid-cli

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

Unterminated quoted string in error handling code of browser launch #568

Closed SmartLayer closed 1 year ago

SmartLayer commented 1 year ago

Describe the bug A syntax error in the error handling code.

To Reproduce

  1. Install though npm. The computer is Linux and have no Chrome.
  2. Run this:
    
    $ mmdc -i test.mmd
    /usr/local/lib/node_modules/mermaid.cli/node_modules/puppeteer/lib/Launcher.js:348
      reject(new Error([
             ^

Error: Failed to launch chrome! /usr/local/lib/node_modules/mermaid.cli/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: 1: Syntax error: Unterminated quoted string

TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md

at onClose (/usr/local/lib/node_modules/mermaid.cli/node_modules/puppeteer/lib/Launcher.js:348:14)
at Interface.<anonymous> (/usr/local/lib/node_modules/mermaid.cli/node_modules/puppeteer/lib/Launcher.js:337:50)
at Interface.emit (node:events:525:35)
at Interface.close (node:internal/readline/interface:533:10)
at Socket.onend (node:internal/readline/interface:259:10)
at Socket.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1359:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v18.13.0



**Expected behavior**

1. mmdc prints an error that it requires Google Chrome
2. (it would be nice to) point out how to configure it to use Chromium instead, because the user may not be able to run Google Chrome at all. Such as my laptop is linux arm64, and there is no Chrome for it.

**Desktop (please complete the following information):**

- OS: Ubuntu 23.04 ARM64 (not AMD64)
- Browser: Chromium
- Version: 114 (Chromium)

**Smartphone (please complete the following information):**

- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
This issue is not asking to support Chromium (although would nice). It's asking to fix the error handling.
aloisklink commented 1 year ago

Hi @weiwu-zhang, it seems like you're using mermaid.cli (very outdated (5 years old)), instead of @mermaid-js/mermaid-cli.

You may want to npm uninstall -g mermaid.cli. If you have a modern version of Node.JS, you can also just use npx @mermaid-js/mermaid-cli and NPM should auto-install the updated package in a cache directory.

I believe puppeteer will automatically download an ARM64 version on MacOS, but I'm not sure if it will on Linux (see https://github.com/puppeteer/puppeteer/issues/550). However, you can create a puppeteer-config.json file that has the contents like: {"executablePath": "/usr/bin/chromium-browser"}, you can then run mmdc --puppeteerConfigFile puppeteer-config.json -i test.mmd and it should work!

Let me know if you're still having this bug (or a different bug) with the latest version of @mermaid-js/mermaid-cli, and I'll re-open this issue.