mermaid-js / mermaid-cli

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

Installation failure when using Snap version of Node.JS #595

Closed janihur closed 11 months ago

janihur commented 11 months ago

Describe the bug I'm trying to install mermaid-cli in Lubuntu LTS 22.04 with

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

but the command fails:

npm ERR! code 1
npm ERR! path /usr/local/lib/node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer
npm ERR! command failed
npm ERR! command sh -c node install.js

To Reproduce Lubuntu version:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:    22.04
Codename:   jammy

Node version, snap installation:

$ which node
/snap/bin/node

$ node --version
v18.17.1

$ npm --version
9.6.7

The installation command:

$ sudo npm install -g @mermaid-js/mermaid-cli
npm ERR! code 1
npm ERR! path /usr/local/lib/node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer
npm ERR! command failed
npm ERR! command sh -c node install.js

npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2023-09-18T06_03_36_188Z-debug-0.log

I don't have /usr/local/lib/node_modules created:

$ l /usr/local/lib/
drwxr-xr-x - root root 2023-09-18 09:05 ./
drwxr-xr-x - root root 2023-08-07 18:17 ../
drwxr-xr-x - root root 2023-08-07 18:17 python3.10/

The full log file: 2023-09-18T06_03_36_188Z-debug-0.log but here the end of the file that hopefully contains all the relevant information:

500 timing reifyNode:node_modules/@mermaid-js/mermaid-cli/node_modules/commander Completed in 261ms
501 timing reifyNode:node_modules/@mermaid-js/mermaid-cli/node_modules/ws Completed in 264ms
502 timing reifyNode:node_modules/@mermaid-js/mermaid-cli/node_modules/readable-stream Completed in 267ms
503 timing reifyNode:node_modules/@mermaid-js/mermaid-cli/node_modules/tar-fs Completed in 269ms
504 timing reifyNode:node_modules/@mermaid-js/mermaid-cli/node_modules/cosmiconfig Completed in 270ms
505 timing reifyNode:node_modules/@mermaid-js/mermaid-cli/node_modules/js-yaml Completed in 286ms
506 timing reifyNode:node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer Completed in 289ms
507 timing reifyNode:node_modules/@mermaid-js/mermaid-cli/node_modules/yargs Completed in 294ms
508 timing reifyNode:node_modules/@mermaid-js/mermaid-cli/node_modules/devtools-protocol Completed in 309ms
509 timing reifyNode:node_modules/@mermaid-js/mermaid-cli/node_modules/@puppeteer/browsers Completed in 312ms
510 timing reifyNode:node_modules/@mermaid-js/mermaid-cli/node_modules/chromium-bidi Completed in 349ms
511 timing reifyNode:node_modules/@mermaid-js/mermaid-cli/node_modules/@types/node Completed in 351ms
512 timing reifyNode:node_modules/@mermaid-js/mermaid-cli Completed in 363ms
513 timing reifyNode:node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer-core Completed in 439ms
514 timing reify:unpack Completed in 441ms
515 timing reify:unretire Completed in 0ms
516 timing build:queue Completed in 3ms
517 timing build:link:node_modules/@mermaid-js/mermaid-cli Completed in 1ms
518 timing build:link:node_modules/@mermaid-js/mermaid-cli/node_modules/@puppeteer/browsers Completed in 1ms
519 timing build:link:node_modules/@mermaid-js/mermaid-cli/node_modules/js-yaml Completed in 1ms
520 timing build:link:node_modules/@mermaid-js/mermaid-cli/node_modules/extract-zip Completed in 1ms
521 timing build:link Completed in 2ms
522 info run puppeteer@19.11.1 postinstall node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer node install.js
523 info run puppeteer@19.11.1 postinstall { code: 1, signal: null }
524 timing reify:rollback:createSparse Completed in 107ms
525 timing reify:rollback:retireShallow Completed in 0ms
526 timing command:install Completed in 116212ms
527 verbose stack Error: command failed
527 verbose stack     at ChildProcess.<anonymous> (/snap/node/7707/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:53:27)
527 verbose stack     at ChildProcess.emit (node:events:514:28)
527 verbose stack     at maybeClose (node:internal/child_process:1091:16)
527 verbose stack     at ChildProcess._handle.onexit (node:internal/child_process:302:5)
528 verbose pkgid puppeteer@19.11.1
529 verbose cwd /home/jani
530 verbose Linux 6.2.0-32-generic
531 verbose node v18.17.1
532 verbose npm  v9.6.7
533 error code 1
534 error path /usr/local/lib/node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer
535 error command failed
536 error command sh -c node install.js
537 verbose exit 1
538 timing npm Completed in 116316ms
539 verbose unfinished npm timer reify 1695017016291
540 verbose unfinished npm timer reify:build 1695017021146
541 verbose unfinished npm timer build 1695017021146
542 verbose unfinished npm timer build:deps 1695017021146
543 verbose unfinished npm timer build:run:postinstall 1695017021151
544 verbose unfinished npm timer build:run:postinstall:node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer 1695017021151
545 verbose code 1
546 error A complete log of this run can be found in: /root/.npm/_logs/2023-09-18T06_03_36_188Z-debug-0.log

Expected behavior

I'm expecting the installation making mmdc command available.

aloisklink commented 11 months ago

It sounds like you have some sort of permission error (maybe because you're using a Node.JS version installed via snap?).

My recommendation is to use npx (also known as npm exec), with:

npx -p @mermaid-js/mermaid-cli mmdc --help

NPM will then automatically install and cache a version of @mermaid-js/mermaid-cli for you, if it isn't already installed! That way you don't need sudo permissions! Please see the Install locally part of the README.md for more info.

janihur commented 11 months ago

Hmm ... I have successfully used snap version of Node.js with other JavaScript software. Here the problem might be the puppeteer module - trying to install puppeteer only fails too. Maybe the module is not "snap Node.js-compatible"?

npx is new to me. I'll check that (hopefully soon).

aloisklink commented 11 months ago

Here the problem might be the puppeteer module - trying to install puppeteer only fails too. Maybe the module is not "snap Node.js-compatible"?

You're right! It looks like puppeteer fails to install properly if Node.js is installed via snap, see https://github.com/puppeteer/puppeteer/issues/7725, https://github.com/puppeteer/puppeteer/issues/7383, and https://github.com/puppeteer/puppeteer/issues/7007.

Thanks for letting us know, since I've actually been recommending people to install Node.JS from snap without knowing that Puppeteer won't install properly on it!

I'll close this as the bug is with the Puppeteer library (and/or with the snap version of Node.JS), and not with us, but it looks like nobody in the Puppeteer library is working on.

If you can, please upvote the https://github.com/puppeteer/puppeteer/issues/7725 issue so that the puppeteer team is aware of the issue!

janihur commented 10 months ago

I was able to install and run mermaid-cli in Lubuntu 22.04 with the following steps.

Install node.js from NodeSource repository, see https://github.com/nodesource/distributions/blob/master/README.md#debian-and-ubuntu-based-distributions

node.js version:

$ which node
/usr/bin/node
$ node --version
v18.18.0
$ npm --version
9.8.1

mermaid-cli installs now succesfully globally:

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

However we're still missing Chromium:

$ mmdc -i example.mmd -o example.svg

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/jani/.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)

Download Chromium:

$ node /usr/lib/node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer/install.js 
Downloading chromium r1108766 - 171.9 MB [====================] 100% 0.0s 
Chromium (1108766) downloaded to /home/jani/.cache/puppeteer/chrome/linux-1108766

Now the mmdc command works:

$ mmdc -i example.mmd -o example.svg
Generating single mermaid chart
$ ls -1 example.*
example.mmd
example.svg