web-dev-qa-db-ja.com

Ubuntu 16.04のPuppeteerが機能しない

Ubuntu Server 16.04で Puppeteer を実行することは可能ですか?このエラーが発生します。

(node:23213) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!
/root/bin/node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux/chrome: error while loading shared libraries: libXss.so.1: cannot open shared object file: No such file or directory


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

    at onClose (/root/bin/node_modules/puppeteer/lib/Launcher.js:750:14)
    at Interface.<anonymous> (/root/bin/node_modules/puppeteer/lib/Launcher.js:739:50)
    at Interface.emit (events.js:333:22)
    at Interface.close (readline.js:414:8)
    at Socket.onend (readline.js:192:10)
    at Socket.emit (events.js:333:22)
    at endReadableNT (_stream_readable.js:1201:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:23213) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:23213) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

この失敗のトラブルシューティングを行い、アプリを実行するにはどうすればよいですか?

2
Lmao 123

それを私が直した。 Linuxを更新し(Sudo-apt get update)、ライブラリーを取得する必要がありました。更新しないと機能しません。

Sudo apt-get install gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget

その後、'--no-sandbox',(myapp.jsからの)起動コード。

1
Lmao 123

クロムの最新バージョンでは、ここでうまくいきました。最近追加された依存関係に注意してください。

Sudo apt-get install libgtk2.0-0 libgtk-3-0 libnotify-dev
Sudo apt-get install libgconf-2-4 libnss3 libxss1
Sudo apt-get install libasound2 libxtst6 xauth xvfb
#recently added dependency
Sudo apt-get install libgbm-dev

Dockerを使用している場合は、Dockerファイルに以下を追加できます。私もDockerでテストしましたが、これは機能します。

RUN apt-get update && \ apt-get install -y libgtk2.0-0 libgtk-3-0 libnotify-dev \ libgconf-2-4 libnss3 libxss1 \ libasound2 libxtst6 xauth xvfb \ libgbm-dev

Puppeteerを呼び出すときに、引数'--no-sandbox'が追加されました。これは、Lmaoの提案と同じです。このオプションがないと機能しませんでした。

参考までに、Ubuntu 20を使用していますが、これはどのディストリビューションでも機能するはずです。

1
Peter Drinnan