简体   繁体   English

无法使用 Puppeteer——错误:无法启动 chrome

[英]Can't Use Puppeteer -- Error: Failed to launch chrome

This is the error I get.这是我得到的错误。 This occurs when the test code is run in the Gitlab CI.当测试代码在 Gitlab CI 中运行时会出现这种情况。

However, it works fine locally.但是,它在本地运行良好。 Someone please help?有人请帮忙吗?

2036 $ npm test

2037 > 10_auth@1.1.3 test /builds/brhanuh/domestic-repair 2037 > 10_auth@1.1.3 测试/builds/brhanuh/domestic-repair

2038 > jest --coverage 'unitTests/' 2038 > 开玩笑 --coverage 'unitTests/'

2039 Error: Failed to launch chrome! 2039 错误:无法启动 chrome!

2040 /builds/brhanuh/domestic-repair/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory 2040 /builds/brhanuh/domestic-repair/node_modules/puppeteer/.local-chromium/linux-686378/chrome-linux/chrome:加载共享库时出错:libX11-xcb.so.1:无法打开共享对象文件:否这样的文件或目录

Install the missing packages using使用安装缺少的包

sudo apt install -y gconf-service libasound2 libatk1.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

Credits to @coldner on the puppetteer issue tracker for assembling the required pkgs.感谢 @coldner 在puppetteer 问题跟踪器上组装所需的 pkg。

If you encounter E: Unable to locate package errors, run sudo apt-get update .如果遇到E: Unable to locate package错误,运行sudo apt-get update

I just wanted to add to @mohammad's answer, that now Puppetteer now has an official troublshooting guide that helps you determine what to install.我只是想补充一下@mohammad 的回答,现在 Puppetteer 现在有一个官方的故障排除指南,可以帮助您确定要安装的内容。

Also, they recommend running the following command to tell which particular packages need installing on *nix systems :此外,他们还建议运行以下命令来判断哪些特定软件包需要安装在 *nix 系统上

ldd chrome | grep not

Or, if you have Chrome installed via Puppetteer via NPM like me:或者,如果你像我一样通过 NPM 通过 Puppetteer 安装了 Chrome:

ldd ./node_modules/puppeteer/.local-chromium/linux-756035/chrome-linux/chrome | grep not

Then, I was able to see what libraries were still missing, and install accordingly.然后,我能够看到仍然缺少哪些库,并相应地进行安装。

you need to install required dependencies您需要安装所需的依赖项

here这里

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

under Chrome headless doesn't launch on UNIX you can findChrome headless doesn't launch on UNIX你可以找到

Debian (e.g. Ubuntu) Dependencies
CentOS Dependencies

For those that are still having this problem, you can try this.对于那些仍然有这个问题的人,你可以试试这个。

sudo apt update && sudo apt install -y ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 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 lsb-release wget xdg-utils sudo apt update && sudo apt install -y ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk- 3-0 libnspr4 libnss3 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 lsb-release wget xdg-utils

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM