midwayjs / midway

🍔 A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade. Works on AWS, Alibaba Cloud, Tencent Cloud and traditional VM/Container. Super easy integrate with React and Vue. 🌈
https://www.midwayjs.org/
MIT License
7.41k stars 576 forks source link

Midway Serverless with puppeteer-core #750

Open chantzekin opened 3 years ago

chantzekin commented 3 years ago

想使用 Midway Serverless 实现阿里云 FC 的「Puppeteer 网页截图应用」模版,把代码迁移过来时候,本地和线上部署皆无法运行,报错如下

线上运行报错如下

{
   "errorMessage": "Failed to launch the browser process!\n/tmp/headless_shell: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory\n\n\nTROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md\n",
   "errorType": "Error",
   "stackTrace": [
      "/tmp/headless_shell: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory",
      "",
      "",
      "TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md",
      "",
      "at onClose (/code/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:193:20)",
      "at helper_js_1.helper.addEventListener (/code/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:183:68)",
      "at emit (events.js:194:15)",
      "at Interface.close (readline.js:379:8)",
      "at onend (readline.js:157:10)",
      "at emit (events.js:194:15)",
      "at endReadableNT (_stream_readable.js:1125:12)",
      "at _tickCallback (internal/process/next_tick.js:63:19)"
   ]
}

本地 macOS 环境报

UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!
/tmp/headless_shell: /tmp/headless_shell: cannot execute binary file

查看「Puppeteer 网页截图应用」模版内包含 headless_shell.tar.gz.fun/root/usr,已拷贝到目录,已配置

package:
  include:
    - headless_shell.tar.gz
    - .fun/*

但是执行 f deploy 时,并无拷贝 .fun/root/usr

想问问,这一块需要如何解决,有没有 Demo 可以参考一下?感谢。

czy88840616 commented 3 years ago

报错是因为fc环境似乎不兼容Puppeteer的库,事实上,所有的需要依赖glibc这些编译的场景都不太兼容。。暂时没有 demo 可用。

czy88840616 commented 3 years ago

@chantzekin 已联系阿里云镜像维护,增加 Puppeteer 默认依赖,估计上线要一阵子,上了之后通知你。

chantzekin commented 3 years ago

@chantzekin 已联系阿里云镜像维护,增加 Puppeteer 默认依赖,估计上线要一阵子,上了之后通知你。

好咧辛苦,先去用 FC 模版摸索下啦

xmsz commented 3 years ago

之前踩坑了一下,阿里云开发需要自己指定puppeterr的lib目录就可以 FC的话用fun install自动处理依赖