Node Js PDF Phantom ENOENT

问题描述

我有一个从 html 正文生成 pdf 的节点 js 服务器,在我的 PC (Windows) 本地安装没有问题,但是当我安装在远程服务器 (Linux) 上时出现此错误

App 3111574 输出:{ 错误:spawn /home/smorenoc/public_html/Casos/node_modules/phantomjs-prebuilt/lib/phantom\bin\phantomjs.exe ENOENT 应用程序 3111574 输出:在 Process.ChildProcess._handle.onexit (internal/child_process.js:240:19) 应用程序 3111574 输出:在 onErrorNT (internal/child_process.js:415:16) 应用程序 3111574 输出:在 process._tickCallback (internal/process/next_tick.js:63:19) 应用程序 3111574 输出: errno: 'ENOENT',应用程序 3111574 输出代码:'ENOENT', 应用程序 3111574 输出:系统调用: 应用程序 3111574 输出:'spawn /home/smorenoc/public_html/Casos/node_modules/phantomjs-prebuilt/lib/phantom\bin\phantomjs.exe', 应用程序 3111574 输出:路径: 应用程序 3111574 输出:'/home/smorenoc/public_html/Casos/node_modules/phantomjs-prebuilt/lib/phantom\bin\phantomjs.exe', 应用程序 3111574 输出:spawnargs: 应用程序 3111574 输出:['/home/smorenoc/public_html/Casos/node_modules/html-pdf/lib/scripts/pdf_a4_portrait.js'] }

/public_html/Casos/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs.exe 实际上存在于服务器中,但似乎没有找到

我无法访问服务器中的终端,我正在通过 cpanel 安装它。

提前致谢

解决方法

Please add the scripts to the Dockerfile:
RUN apk add fontconfig ttf-dejavu
RUN apk add --no-cache curl &&
cd /tmp && curl -Ls https://github.com/dustinblackman/phantomized/releases/download/2.1.1/dockerized-phantomjs.tar.gz | tar xz &&
cp -R lib lib64 / &&
cp -R usr/lib/x86_64-linux-gnu /usr/lib &&
cp -R usr/share /usr/share &&
cp -R etc/fonts /etc &&
apk del curl

I did it and it works well. (node:12.20-alpine3.12)