"html-pdf: Failed to load PhantomJS module.

วิธีแก้ไขเอาขึ้น server linux แล้ว "error phantomjs-prebuilt"
1. ลบ lib: phantomjs-prebuilt ด้วยคำสั่ง rm -rf node_modules/phantomjs-prebuilt
2.ติดตั้งใหม่ ด้วยคำสั่ง npm install phantomjs-prebuilt
---------------------------------------------


ref: https://github.com/marcbachmann/node-html-pdf/issues/437
ref: https://github.com/marcbachmann/node-html-pdf/issues/212
ref: https://www.javascripttutorial.net/nodejs-tutorial/npm-list/
 
@ganeshmogare
Copy link

@ganeshmogare ganeshmogare commented on Jun 4, 2018

hi ,i'm trying to use html-pdf module , but it throws "html-pdf: Failed to load PhantomJS module. You have to set the path to the PhantomJS binary using 'options.phantomPath" error ,
steps i tried to resolve :
1. installed html-pdf
2. rm -rf node_modules/phantomjs-prebuilt (or npm uninstall phantomjs-prebuilt)
3. npm install phantomjs-prebuilt@2.1.13 (and phantomjs-prebuilt@2.1.4)

but no use , it was throwing same error , then i assignedoptions.phantomPath to node_modules\phantomjs-prebuilt

after that it is throwing following error , please help

{"error":{"message":"spawn EACCES","stack":"Error: spawn EACCES\\n at _errnoException (util.js:1022:11)\\n at ChildProcess.spawn (internal/child_process.js:323:11)\\n at Object.exports.spawn (child_process.js:502:9)\\n at PDF.PdfExec [as exec] (/root/PGServerJs/node_modules/html-pdf/lib/pdf.js:88:28)\\n at PDF.PdfToFile [as toFile] (/root/PGServerJs/node_modules/html-pdf/lib/pdf.js:83:8)\\n

i tried to change the permissions of phantomjs , but still it is not working


Copy link

@Paul-JO Paul-JO commented on Feb 26, 2019

In my case this solved the issue:
$ (sudo) npm link phantomjs-prebuilt

I am not an expert, but it seems that since html-pdf is installed globally you have to link these global installations to your project. So my installation looks like this:

$ (sudo) npm install html-pdf -g
$ (sudo) npm link html-pdf
$ (sudo) npm link phantomjs-prebuilt

If this is somehow not the real way to go, I would be happy about other suggestions as I am planning to use this for an upcoming project.


Copy link

@yogieputra8 yogieputra8 commented on Feb 15, 2017

@glenn-allen thank you. I combined your solution with this: uncss/uncss#165 and it works well.

Here's how I resolve my error:

  1. install this module html-pdf (mine is Ver2.1.0)
  2. Go to node_modules folder then delete folder phantomjs-prebuilt that come along with this html-pdf installation, then do npm install phantomjs-prebuilt@2.1.13 (thanks to @glenn-allen 👍🏻).
  3. Do sudo apt-get install libfontconfig. (see this uncss/uncss#165)

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

J2EE คืออะไร

วิธีแก้ : แก้ไขตารางแล้ว save ไม่ได้ ต้องสร้างใหม่ - Saving changes is not permitted in SQL Server Management Studio

การออกแบบ RESTful API - วิธีปฏิบัติที่ดี