问题
root@test:/data/a8service/source# npm i
puppeteer@5.5.0 install /data/a8service/source/node_modules/puppeteer
node install.js
ERROR: Failed to set up Chromium r818858! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.
[Error: EACCES: permission denied, mkdir '/data/a8service/source/node_modules/puppeteer/.local-chromium'] {
errno: -13,
code: 'EACCES',
syscall: 'mkdir',
path: '/data/a8service/source/node_modules/puppeteer/.local-chromium'
}
npm WARN @nestjs/mapped-types@0.0.5 requires a peer of @nestjs/common@^7.0.8 but none is installed. You must install peer dependencies yourself.
npm WARN app8@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/pm2/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! puppeteer@5.5.0 install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the puppeteer@5.5.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-03-26T02_00_17_794Z-debug.log
问题一:permission denied, mkdir…
npm install puppeteer --ignore-scripts
能安装成功,但是无效
npm install puppeteer --unsafe-perms
无效
npm install puppeteer --unsafe-perms=true
无效
sudo npm install -g puppeteer --unsafe-perm=true
或者
sudo npm install puppeteer --unsafe-perm=true
root@test:/data/a8service/source# sudo npm install -g puppeteer --unsafe-perm=true
sudo: npm: command not found
无效
root@test:/data/.node/bin# which npm
/data/.node/bin/npm
sudo ln -s /data/.node/bin/node /usr/bin/node
sudo ln -s /data/.node/bin/npm /usr/bin/npm
解决上面命令无效的问题
root@test:/data/a8service/source# sudo npm install puppeteer --unsafe-perm=true
puppeteer@5.5.0 install /data/a8service/source/node_modules/puppeteer
node install.js
Downloading Chromium r818858 - 132.1 Mb [====================] 100% 0.0s
Chromium (818858) downloaded to /data/a8service/source/node_modules/puppeteer/.local-chromium/linux-818858
npm WARN @nestjs/mapped-types@0.0.5 requires a peer of @nestjs/common@^7.0.8 but none is installed. You must install peer dependencies yourself.
npm WARN app8@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/pm2/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
- puppeteer@5.5.0
added 12 packages from 8 contributors and audited 1798 packages in 23.756s
53 packages are looking for funding
run npm fund
for details
found 4336 vulnerabilities (4315 low, 15 moderate, 6 high)
run npm audit fix
to fix them, or npm audit
for details
至此安装成功
问题二:Failed to launch the browser process
又产生了新的问题
“Failed to launch the browser process!\n[0326/102320.089584:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.\n\n\nTROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md\n
const browser = await puppeteer.launch({
headless: true,
args: [”–no-sandbox"]
});
增加–no-sandbox参数,问题解决。
至此问题解决
问题三:生成的pdf中文乱码
看我博客的另一个文章,专门有讲。
解决pdf中文乱码
问题四:error while loading shared libraries: libxkbcommon.so.0
根据提示,
https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
可能是缺少依赖项,由于不确定是哪一个,也不能一个一个的安装,那安装到什么时候了,所以以所有依赖项全部安装。
apt-get update
apt install 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