CentOS 7环境下安装与运行PagedJS时的Puppeteer相关问题求助
CentOS 7下PagedJS-cli运行失败:Puppeteer依赖问题无法解决
我在CentOS 7环境下尝试使用PagedJS-cli将HTML文件转换为PDF,遇到了多个问题,尝试了几种方法仍无法解决,具体情况如下:
环境信息
- 操作系统:CentOS 7
- Node.js版本:v17.0.1(同时试过最新LTS版本,问题一致)
- npm版本:v8.1.0
问题1:全局安装PagedJS时出现Puppeteer错误
当我执行全局安装命令:
npm install -g pagedjs-cli pagedjs
出现了弃用警告和Puppeteer相关的安装错误:
npm WARN deprecated @babel/polyfill@7.12.1: This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when neded). See the @babel/polyfill docs for more information. npm WARN deprecated core-js@2.6.12: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 enginewhims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js. npm ERR! code 1 npm ERR! path /root/.nvm/versions/node/v14.17.5/lib/node_modules/pagedjs-cli/node_modules/puppeteer npm ERR! command failed npm ERR! command sh -c node install.js npm ERR! internal/modules/cjs/loader.js:905 npm ERR! throw err; npm ERR! ^ npm ERR! npm ERR! Error: Cannot find module '/root/.nvm/versions/node/v14.17.5/lib/node_modules/pagedjs-cli/node_modules/puppeteer/install.js' npm ERR! at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) npm ERR! at Function.Module._load (internal/modules/cjs/loader.js:746:27) npm ERR! at Function.executeUserEntryPoint [as runMain] (internal/run_main.js:76:12) npm ERR! at internal/main/run_main_module.js:17:47 { npm ERR! code: 'MODULE_NOT_FOUND', npm ERR! requireStack: [] npm ERR! }
单独执行全局安装Puppeteer的命令npm install -g puppeteer时,会出现完全相同的错误(没有上述弃用警告)。
问题2:本地安装成功但运行时缺少依赖库
我改用本地安装命令:
npm install pagedjs-cli pagedjs
安装过程顺利,执行npm ls显示相关包已成功安装:
├── pagedjs-cli@0.1.6 ├── pagedjs@0.2.0 └── puppeteer@10.4.0
但当我执行命令运行PagedJS-cli时:
npx pagedjs-cli example.html -o result.pdf
出现了浏览器启动失败的错误,提示缺少共享库:
Loading: example.htmlError: Failed to launch the browser process! /home/sophivorus/node_modules/puppeteer/.local-chromium/linux-901912/chrome-linux/chrome: error while loading shared libraries: libatk-bridge-2.0.so.0: cannot open shared object file: No such file or directory at onClose (/home/sophivorus/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:197:20) at Interface.<anonymous> (/home/sophivorus/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:187:68) at Interface.emit (events.js:412:35) at Interface.close (readline.js:530:8) at Socket.onend (readline.js:254:10) at Socket.emit (events.js:412:35) at endReadableNT (internal/streams/readable.js:1334:12) at processTicksAndRejections (internal/process/task_queues.js:82:21)
尝试的解决方法及结果
- 安装缺失的共享库:执行
yum install libatk-bridge-2.0.so.0,安装完成后执行ldconfig -p | grep libatk-bridge-2.0.so.0显示库已成功安装:
libatk-bridge-2.0.so.0 (libc6) => /lib/libatk-bridge-2.0.so.0
- 尝试直接调用本地安装的PagedJS-cli二进制文件:
/home/sophivorus/node_modules/.bin/pagedjs-cli example.html -o result.pdf
但仍出现与之前完全相同的错误。
我已经尝试了不同版本的Node.js(最新版和LTS版本),问题依旧存在。希望能得到大家的技术帮助,解决这个Puppeteer依赖导致的PagedJS-cli无法运行的问题。
内容的提问来源于stack exchange,提问作者Sophivorus
相关产品推荐
相关产品推荐

