mermaid-js / mermaid-cli

Command line tool for the Mermaid library
MIT License
2.4k stars 227 forks source link

Error: Could not find Chromium (rev. 1108766) #650

Closed ubiman closed 7 months ago

ubiman commented 7 months ago

The script (file: input.mmd):

flowchart LR
  A-->B

The command line:

mmdc -i input.mmd -o input.png

The error message:

Error: Could not find Chromium (rev. 1108766). This can occur if either
 1. you did not perform an installation before running the script (e.g. `npm install`) or
 2. your cache path is incorrectly configured (which is: /home/jfr/.cache/puppeteer).
For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.
    at ChromeLauncher.resolveExecutablePath (file:///usr/lib/node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer-core/lib/esm/puppeteer/node/ProductLauncher.js:263:27)
    at ChromeLauncher.executablePath (file:///usr/lib/node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer-core/lib/esm/puppeteer/node/ChromeLauncher.js:176:25)
    at ChromeLauncher.computeLaunchArguments (file:///usr/lib/node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer-core/lib/esm/puppeteer/node/ChromeLauncher.js:93:37)
    at async ChromeLauncher.launch (file:///usr/lib/node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer-core/lib/esm/puppeteer/node/ProductLauncher.js:57:28)
    at async run (file:///usr/lib/node_modules/@mermaid-js/mermaid-cli/src/index.js:404:19)
    at async cli (file:///usr/lib/node_modules/@mermaid-js/mermaid-cli/src/index.js:184:3)

The environment:

When installing mermaid-cli (@latest):

 sudo npm install -g @mermaid-js/mermaid-cli@latest

 npm WARN deprecated puppeteer@19.11.1: < 21.5.0 is no longer supported

I did reinstall and reboot everything many times. I've looked everything and everywhere I could. I've spent many many hours. I am a little desperate. I don't know what else to do.

Please, any help will be very much appreciated. Thank you!!!

tautschnig commented 7 months ago

For all that I can tell the fix is to upgrade the puppeteer dependency. See #627 (and #646).

ubiman commented 7 months ago

Thank you for the fast reply. Appreciated!

I did replicate the change in "package.json" mentioned in #646. It didn't fix the error when running mmdc. I tried reinstalling mermaid-cli afterward just in case, but as I suspected, it just wiped out my manual update to package.json. Bottom line, I'm not skilled enough to understand what I am doing here.

So, I downgraded my way down to mermaid-cli 9.1.7. Although, the install still complains about the puppeteer version (the version on my machine is 22.0.0), the mmdc command now works with mermaid 9.1.7. I am OK with this workaround.

Since I seem to be the only one having this issue, I probably messed up something in my first installation attempt. Apologies.

aloisklink commented 7 months ago

@ubiman, can you try running npx @mermaid-js/mermaid-cli@latest?

You can use echo 'info' | npx @mermaid-js/mermaid-cli --input '-' --output 'out.svg' to test rendering a super basic info diagram.

My gut feeling is that the issue is with sudo.

npx is quite nice, since it automatically installs @mermaid-js/mermaid-cli into a cache directory if it's not already installed.


For all that I can tell the fix is to upgrade the puppeteer dependency. See https://github.com/mermaid-js/mermaid-cli/issues/627 (and https://github.com/mermaid-js/mermaid-cli/pull/646).

That's just a deprecation warning, it should work fine on the current version (the older version is even faster, due to some changes in the newer versions of puppeteer).

ubiman commented 7 months ago

@aloisklink, using npx with the latest version, no output is produced. It doesn't show any error message though. Not sure why. Here's the full command and the full result of it:

$ npx @mermaid-js/mermaid-cli@latest -i input.mmd -o out.svg
Need to install the following packages:
@mermaid-js/mermaid-cli@10.8.0
Ok to proceed? (y) y
npm WARN deprecated puppeteer@19.11.1: < 21.5.0 is no longer supported

As with mmdc, if I execute npx using version 9, then it works. Here's the command and result:

$ npx @mermaid-js/mermaid-cli@9.0.0 -i input.mmd -o out.svg
Need to install the following packages:
@mermaid-js/mermaid-cli@9.0.0
Ok to proceed? (y) y
npm WARN deprecated puppeteer@13.7.0: < 21.5.0 is no longer supported
Generating single mermaid chart

All my tests show that mermaid-cli 9.1.7 and versions below work for me. Everything above mermaid-cli 9.1.7 seems to be incompatible with something in my environment.

I would love to use the newer mermaid version as some of my diagrams use the ~~~ connector (apparently not supported in 9.1.7), but the older version is better than nothing.

Thank you for your support!

aloisklink commented 7 months ago

Unfortunately, npx doesn't show an installation errors, it just silently exists. So I'm guessing it's an error when trying to install puppeteer.

Do any error messages show up when you run npm install @mermaid-js/mermaid-cli? (just as a warning, npm install @mermaid-js/mermaid-cli will download mmdc only into your current folder, so make a temporary directory first!).

I think I know what the issue is: Puppeteer v19.0.0 (used by mermaid-cli v9.1.7) now installs into the ~/.cache/puppeteer folder by default. My gut feeling is that something is going wrong there (I wonder if the sudo install @mermaid-js/mermaid-cli might have changed the owner of that folder to the root user, instead of your default user).

As an example, if I purposely break the ~/.cache/puppeteer folder, this is the error I get:

node@bcc2238841e0:~/test$ npm install @mermaid-js/mermaid-cli
npm WARN deprecated puppeteer@19.11.1: < 21.5.0 is no longer supported
npm ERR! code 1
npm ERR! path /home/node/test/node_modules/puppeteer
npm ERR! command failed
npm ERR! command sh -c node install.js
npm ERR! ERROR: Failed to set up Chromium r1108766! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.
npm ERR! Error: ENOTDIR: not a directory, mkdir '/home/node/.cache/puppeteer/chrome'
npm ERR!     at async mkdir (node:internal/fs/promises:850:10)
npm ERR!     at async install (/home/node/test/node_modules/@puppeteer/browsers/lib/cjs/install.js:64:9)
npm ERR!     at async downloadBrowser (/home/node/test/node_modules/puppeteer/lib/cjs/puppeteer/node/install.js:69:24) {
npm ERR!   errno: -20,
npm ERR!   code: 'ENOTDIR',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/home/node/.cache/puppeteer/chrome'
npm ERR! }

npm ERR! A complete log of this run can be found in: /home/node/.npm/_logs/2024-02-18T23_21_22_471Z-debug-0.log

You might also want to try deleting your ~/.cache/puppeteer folder and/or your ~/.cache folder and let puppeteer re-create it.

ubiman commented 7 months ago

Ok. All is working now.

I tried deleting the puppeteer cache, but it didn't change the result I was getting.

Since I remembered installing the latest version of puppeteer and that it was higher than 19.11.1, I researched for a way to list the packages installed with NPM. That led me to do the following command:

$ npm list
usr@ /home/usr
├── @mermaid-js/mermaid-cli@10.8.0
├── mermaid@10.8.0
└── puppeteer@22.1.0

That is when I saw mermaid@10.8.0 which I believe is something different than mermaid-cli and that I installed at the very beginning (pretty sure I installed it before mermaid-cli) and forgot about.

After removing mermaid and reinstalling mermaid-cli, it started to work! Not a 100% sure that having mermaid beside mermaid-cli was the root cause of my problem, but I can't see anything else.

NOTE: the warning message npm WARN deprecated puppeteer@19.11.1: < 21.5.0 is no longer supported is still displayed when installing mermaid-cli, but it doesn't seem to cause an issue.

Many thanks to @aloisklink and @tautschnig for their help and generosity with their time!!!

aloisklink commented 7 months ago

Glad to have helped :) npm can be pretty unintuitive sometimes!

I'm marking this issue as closed, but let me know if you have any other issues!