debian puppeteer 安装问题汇总

ERROR: Failed to download Chromium r588429! Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" env variable to skip download.
{ Error: EACCES: permission denied, mkdir '/data/wwwroot/example/dispa/node_modules/puppeteer/.local-chromium'
  errno: -13,
  code: 'EACCES',
  syscall: 'mkdir',
  path: '/data/wwwroot/example/dispa/node_modules/puppeteer/.local-chromium' }
npm WARN dispa@1.0.0 No description
npm WARN dispa@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! puppeteer@1.8.0 install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the puppeteer@1.8.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/2018-09-11T01_37_36_695Z-debug.log

直接看一开始的 Error 还以为是网络问题没法下载 chrome ,尝试设置了 PUPPETEER_SKIP_CHROMIUM_DOWNLOAD 没用
才看见底下的 permission denied 原来是没权限
运行 sudo npm i puppeteer 安装即可

node:30630) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
/data/wwwroot/example/dispa/node_modules/puppeteer/.local-chromium/linux-588429/chrome-linux/chrome: error while loading shared libraries: libasound.so.2: cannot open shared object file: No such file or directory


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

    at onClose (/data/wwwroot/example/dispa/node_modules/puppeteer/lib/Launcher.js:333:14)
    at Interface.helper.addEventListener (/data/wwwroot/example/dispa/node_modules/puppeteer/lib/Launcher.js:322:50)
    at emitNone (events.js:111:20)
    at Interface.emit (events.js:208:7)
    at Interface.close (readline.js:368:8)
    at Socket.onend (readline.js:147:10)
    at emitNone (events.js:111:20)
    at Socket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
(node:30630) 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(). (rejection id: 1)
(node:30630) [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.

经过翻看 issues 这个问题是因为依赖问题导致的
执行 wget -qO- --no-check-certificate https://raw.githubusercontent.com/Garbee/puppeteer/cd00f7d936c942f8f378a332401024e501b186ce/utils/linux/debian-check.sh | bash 后,在 shell 执行列出的命令,安装相关依赖。

(node:32460) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
[0911/100703.525676:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.


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

    at onClose (/data/wwwroot/example/dispa/node_modules/puppeteer/lib/Launcher.js:333:14)
    at Interface.helper.addEventListener (/data/wwwroot/example/dispa/node_modules/puppeteer/lib/Launcher.js:322:50)
    at emitNone (events.js:111:20)
    at Interface.emit (events.js:208:7)
    at Interface.close (readline.js:368:8)
    at Socket.onend (readline.js:147:10)
    at emitNone (events.js:111:20)
    at Socket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
(node:32460) 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(). (rejection id: 1)
(node:32460) [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.

设置 --no-sandbox 参数:
const browser = await puppeteer.launch({headless: true, args:['--no-sandbox']});
或者切换到非 root 用户