由于 Puppeteer 问题无法安装 PagedJS

Can't install PagedJS due to a Puppeteer issue

当我尝试使用推荐的 npm install -g pagedjs-cli pagedjs install PagedJS 时,我得到:

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 (https://babeljs.io/docs/en/babel-polyfill) 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/modules/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! }

如果我 运行 npm install -g puppeteer 我得到完全相同的错误(减去警告)。

我尝试使用 npm install pagedjs-cli pagedjs 进行本地安装,一切正常(当我 运行 npm ls 我得到:

├── pagedjs-cli@0.1.6
├── pagedjs@0.2.0
└── puppeteer@10.4.0

这似乎表明相关包已在本地成功安装)。但是当我尝试使用 npx pagedjs-cli example.html -o result.pdf 运行 PagedJS 时,我得到:

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

TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
    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

这似乎表明该库已成功安装)。但是,当我重试 npx pagedjs-cli example.html -o result.pdf 时,我得到了完全相同的错误。如果我用 /home/sophivorus/node_modules/.bin/pagedjs-cli example.html -o result.pdf 避免 npx 我会得到同样的错误。

我在 CentOS 7 上,运行正在使用最新的节点和 npm:

node -v
v17.0.1

npm -v
8.1.0

我也试过最新的 LTS 版本。感谢您的帮助!

您尝试使用的库 (pagedjs) 似乎非常不完整,它基于其他库的过时和弃用版本,并且仅由一名开发人员维护。它总共只有大约 100 次提交。我建议切换到 jsPDF。它有超过 4000 个分叉,我对提交完全保持沉默。它得到积极维护并且非常受欢迎。尽管如此,这只是我首先发现的。也许你能找到更好的图书馆...

这个问题也可能对您有所帮助: Generate pdf from HTML in div using Javascript

包有另一个名字...

repoquery --list at-spi2-atk.x86_64

liblib64 不是一回事:

  • ldd /usr/lib64/libatk-bridge-2.0.so.0.0.0
  • ldd /lib/libatk-bridge-2.0.so.0