问题描述
我写了一个小木偶程序,让我登录Twitter并检查了几件事。在Mac OS Catalina上本地运行,但是在VPS ubuntu 18.04 lts上无法运行。并在开始时显示了一条日志:
/root/retwiter/node_modules/puppeteer/.local-chromium/linux-800071/chrome-linux/chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
我有2个运行浏览器的配置: 本地:
{
headless: false,defaultviewport: null,args: [
'--window-size=1920,1080'
]
}
vps:
{
headless: true,args: [
'--no-sandBox','--disable-setuid-sandBox'
]
}
解决方法
我认为您缺少库 libnss3 ,请尝试使用
进行安装sudo apt-get install libnss3-dev
如果这还不够,请为pupetter安装所有部门
sudo apt-get 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
,
您可以将 AWS Elastic Beanstalk 配置文件 (.ebextensions
) 添加到您的 Web 应用程序的源代码中,以配置您的环境并自定义其中包含的 AWS 资源。
在我们的例子中,如果我们不启用 EPEL 并且如果我们继续安装 Chromium 作为 npm install 的一部分,由于 libatk-1.0.so.0
不可用,Puppeteer 无法启动 Chromium。
热修复
将以下内容添加到您的应用根目录:
- 创建一个
.npmrc
文件。 - 将以下内容添加到您的
.npmrc
文件中:
unsafe-perm=true
.npmrc
文件定义了 npm 在运行命令时的行为方式。将 unsafe-perm
设置为 true
会在运行包脚本时禁止 UID/GID 切换。设置 unsafe-perm 标志以使用 root 权限运行脚本。
- 来源@unsafe-perm
- 创建一个
.ebextensions
文件夹。 - 在
.ebextensions
文件夹中,创建一个01_enableEPEL.config
文件并添加以下内容。
commands:
01_enableEPEL:
command: sudo amazon-linux-extras install epel -y
- 在
.ebextensions
文件夹中,创建一个02_installEPELPackages.config
文件并添加以下内容
packages:
yum:
chromium: []
您可以在我的 GitHub @ https://github.com/amarinediary/Marionette
上查看相同的指南