我正在尝试在predix-web-starter应用程序中使用Google Chrome Puppeteer。当我在Windows上本地运行代码时,它可以完美运行。将其推送到Predix后,当我运行包含Puppeteer代码的部件时,将导致错误。似乎有一些缺少的库问题(不确定是什么)。
简而言之,如何让Puppeteer在Predix上运行?

Predix-web-starter:https://github.com/PredixDev/predix-webapp-starter
木偶:https://www.npmjs.com/package/puppeteer

木偶代码:

const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://news.ycombinator.com', {waitUntil: 'networkidle'});
await page.pdf({path: 'hn.pdf', format: 'A4'});
await browser.close();
})();


日志:

2017-11-07T12:40:16.19+0530 [App/0] ERR /home/vcap/app/node_modules/puppeteer/.local-chromium/linux-508693/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
2017-11-07T12:40:16.19+0530 [App/0] ERR TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
2017-11-07T12:40:16.19+0530 [App/0] ERR     at Interface.close (readline.js:319:8)
2017-11-07T12:40:16.19+0530 [App/0] ERR     at endReadableNT (_stream_readable.js:974:12)
2017-11-07T12:40:16.19+0530 [App/0] ERR Potentially unhandled rejection [3] Error: Failed to launch chrome!
2017-11-07T12:40:16.19+0530 [App/0] ERR     at onClose (/home/vcap/app/node_modules/puppeteer/node6/Launcher.js:262:14)
2017-11-07T12:40:16.19+0530 [App/0] ERR     at emitNone (events.js:91:20)
2017-11-07T12:40:16.19+0530 [App/0] ERR     at Interface.emit (events.js:186:7)
2017-11-07T12:40:16.19+0530 [App/0] ERR     at _combinedTickCallback (internal/process/next_tick.js:74:11)
2017-11-07T12:40:16.19+0530 [App/0] ERR     at Interface.helper.addEventListener (/home/vcap/app/node_modules/puppeteer/node6/Launcher.js:251:50)
2017-11-07T12:40:16.19+0530 [App/0] ERR     at Socket.onend (readline.js:106:10)
2017-11-07T12:40:16.19+0530 [App/0] ERR     at emitNone (events.js:91:20)
2017-11-07T12:40:16.19+0530 [App/0] ERR     at Socket.emit (events.js:186:7)
2017-11-07T12:41:15.21+0530 [RTR/2] OUT puppeter-arjun-app.run.aws-usw02-pr.ice.predix.io - [2017-11-07T07:10:16.196+0000] "GET /puppeteer HTTP/1.1" 502 0 67 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36" "10.72.11.93:2263" "10.72.2.213:61322" x_forwarded_for:"-" x_forwarded_proto:"http" vcap_request_id:"7d0f3007-914a-42d4-536d-b94eb8d2fb6c" response_time:59.022647288 app_id:"02063159-96d9-43c5-a3e9-77f4e72339f4" app_index:"-" x_b3_traceid:"4f11f468be4b6817" x_b3_spanid:"4f11f468be4b6817" x_b3_parentspanid:"-"
2017-11-07T12:41:15.21+0530 [RTR/2] OUT

最佳答案

最近发现,使用cloudfoundry/apt-buildpackcloudfoundry/nodejs-buildpack,可以通过将共享库包含在apt.yml中来安装它们。但是predix不允许multibuildpacks push,因此出于未知原因,我尝试使用cloudfoundry/multi-buildpack而不成功。我解决问题的方法是创建一个自定义buildpack,从apt接收代码,将其放在nodejs buildpack上,然后在manifest.yml上包括git repository url。
这是我的custom buildpack

10-06 03:50