node-html-pdf: "html-pdf: Failed to load PhantomJS module. You have to set the path to the PhantomJS binary using \'options.phantomPath
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
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 22
In my case this solved the issue:
$ (sudo) npm link phantomjs-prebuiltI 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-prebuiltIf 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.
Install PhantomJs
https://www.vultr.com/docs/how-to-install-phantomjs-on-ubuntu-16-04 Check phantomjs --version -> O/p 2.1.1
Then in the htm-pdf module html-pdf -> lib -> pdf.js Add the line after “this.options = options || {}” this.options.phantomPath = “/usr/local/bin/phantomjs”
Very thanks this solution work for me in serverless.
My steps were:
$ npm install phantomjs-prebuiltpdf.create(html,{ "phantomPath": "./node_modules/phantomjs-prebuilt/bin/phantomjs" });Then 🚀
I’m using
2.1.16and this worked for menpm install phantomjs-prebuilt@2.1.16 --update-binaryThis is how I resolved mine. I performed an upgrade on my Docker node, transitioning from
node:16.15.0-slimtonode:20.5.0. It’s working perfectly now.I have Win10 and Node 6.11 and NPM 6.6.0-next.0 with
html-pdf^2.2.0 in mypackage.jsonfor one of my projects. I too faced this error even after redoingnpm install html-pdf. I just did anpm link html-pdfthat resulted ind:\nodejs\html-pdf -> d:\nodejs\node_modules\html-pdf\bin\index.js> phantomjs-prebuilt@2.1.16 install d:\nodejs\node_modules\html-pdf\node_modules\phantomjs-prebuilt> node install.jsPhantomJS not found on PATHDownloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-windows.zipSaving to C:\Users\vijaya.m\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zipReceiving...[========================================] 99%Received 17767K total.Extracting zip contentsRemoving D:\nvm\v6.14.4\node_modules\html-pdf\node_modules\phantomjs-prebuilt\lib\phantomCopying extracted folder C:\Users\vijaya.m\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip-extract-1580985378446\phantomjs-2.1.1-windows -> D:\nvm\v6.14.4\node_modules\html-pdf\node_modules\phantomjs-prebuilt\lib\phantomWriting location.js fileDone. Phantomjs binary available at D:\nvm\v6.14.4\node_modules\html-pdf\node_modules\phantomjs-prebuilt\lib\phantom\bin\phantomjs.exe+ html-pdf@2.2.0added 82 packages from 77 contributors in 79.333sAnd pdf.create(…) works good now.
In
optionsofpdf.create(html,options)add below :"phantomPath": "./node_modules/phantomjs-prebuilt/bin/phantomjs",.Notice I am mentioned
phantomjs-prebuilt& not defaultphantomjs.I was able to run thie library by above methods on all devices without any global installations.
Hi,
I’m facing the same issue. We’re using version 2.1.0
Thank you for helping
I faced the same error and I downgrade my node version from v16.14.1 to v14.18.1 and it is working fo me now
First install phantomjs using, brew tap homebrew/cask brew cask install phantomjs
Try if “phantomjs -v” works.
If works, then type “which phantomjs”, this is where the /path/to/phantomjs
Then edit /usr/local/bin/html-pdf > lib > pdf.js Add the line after “this.options = options || {}” this.options.phantomPath = “/path/to/phantomjs”
This solved the problem for me.