node-html-pdf icon indicating copy to clipboard operation
node-html-pdf copied to clipboard

"html-pdf: Failed to load PhantomJS module. You have to set the path to the PhantomJS binary using \'options.phantomPath

Open ganeshmogare opened this issue 6 years ago • 22 comments

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 [email protected] (and [email protected])

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

ganeshmogare avatar Jun 04 '18 14:06 ganeshmogare

Hi,

I'm facing the same issue. We're using version 2.1.0

Thank you for helping

jourdan-qe avatar Jun 04 '18 15:06 jourdan-qe

try to install like I do......... Go to your node_modules folder through terminal and use the command "sudo node ./install.js" or "sudo node ./install.js -f"............ this will definitely install this module.....

varuntblr avatar Jan 09 '19 12:01 varuntblr

html-pdf: Failed to load PhantomJS module. You have to set the path to the PhantomJS binary using 'options.phantomPath' AssertionError [ERR_ASSERTION]: html-pdf: Failed to load PhantomJS module. You have to set the path to the PhantomJS binary using 'options.phantomPath' Sorry, an error has occured, Requested page not found!

ganeshpaiya avatar Feb 01 '19 07:02 ganeshpaiya

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.

Paul-JO avatar Feb 26 '19 14:02 Paul-JO

Thanks @Paul-JO Working fine

balaji4191 avatar Mar 01 '19 07:03 balaji4191

Great that it works @balaji4191 I noticed some issues after doing this when installing new packages as those linked packages do not contain repository fields in their package descriptions. To solve this one would need to remove the node_modules folder, install the new package and to link the html-pdf and phantomjs again.

Paul-JO avatar Mar 01 '19 08:03 Paul-JO

Are you using html-pdf on the frontend or the server? I've been using it on the server without any trouble but I just tried to use it on the frontend in order to save the data transfered (up to 1mb per generated PDF), and this error happened...

stemtra avatar Jul 22 '19 17:07 stemtra

aa

Venugopal619 avatar Aug 14 '19 06:08 Venugopal619

I also encountered this problem.

Young6118 avatar Sep 03 '19 09:09 Young6118

I have Win10 and Node 6.11 and NPM 6.6.0-next.0 with html-pdf ^2.2.0 in my package.json for one of my projects. I too faced this error even after redoing npm install html-pdf. I just did a npm link html-pdf that resulted in d:\nodejs\html-pdf -> d:\nodejs\node_modules\html-pdf\bin\index.js > [email protected] install d:\nodejs\node_modules\html-pdf\node_modules\phantomjs-prebuilt > node install.js PhantomJS not found on PATH Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-windows.zip Saving to C:\Users\vijaya.m\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip Receiving... [========================================] 99% Received 17767K total. Extracting zip contents Removing D:\nvm\v6.14.4\node_modules\html-pdf\node_modules\phantomjs-prebuilt\lib\phantom Copying 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\phantom Writing location.js file Done. Phantomjs binary available at D:\nvm\v6.14.4\node_modules\html-pdf\node_modules\phantomjs-prebuilt\lib\phantom\bin\phantomjs.exe + [email protected] added 82 packages from 77 contributors in 79.333s

And pdf.create(...) works good now.

VijayakumarManickam avatar Feb 06 '20 10:02 VijayakumarManickam

An npm rebuild might be needed, see https://github.com/Medium/phantomjs, section "Cross-Platform Repositories". This was the reason, when we encountered this problem. See also pull request #555

jdoose avatar Feb 20 '20 07:02 jdoose

I'm using 2.1.16 and this worked for me npm install [email protected] --update-binary

NathanD14 avatar Apr 09 '20 19:04 NathanD14

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.

Nana7926 avatar Apr 10 '20 00:04 Nana7926

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"

imvikaskohli avatar May 02 '20 06:05 imvikaskohli

I have Win10 and Node 6.11 and NPM 6.6.0-next.0 with html-pdf ^2.2.0 in my package.json for one of my projects. I too faced this error even after redoing npm install html-pdf. I just did a npm link html-pdf that resulted in d:\nodejs\html-pdf -> d:\nodejs\node_modules\html-pdf\bin\index.js > [email protected] install d:\nodejs\node_modules\html-pdf\node_modules\phantomjs-prebuilt > node install.js PhantomJS not found on PATH Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-windows.zip Saving to C:\Users\vijaya.m\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip Receiving... [========================================] 99% Received 17767K total. Extracting zip contents Removing D:\nvm\v6.14.4\node_modules\html-pdf\node_modules\phantomjs-prebuilt\lib\phantom Copying 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\phantom Writing location.js file Done. Phantomjs binary available at D:\nvm\v6.14.4\node_modules\html-pdf\node_modules\phantomjs-prebuilt\lib\phantom\bin\phantomjs.exe + [email protected] added 82 packages from 77 contributors in 79.333s

And pdf.create(...) works good now.

This worked for me Running npm link html-pdf and getting the output as above.

NeniEmSu avatar Dec 10 '20 14:12 NeniEmSu

I have Win10 and Node 6.11 and NPM 6.6.0-next.0 with html-pdf ^2.2.0 in my package.json for one of my projects. I too faced this error even after redoing npm install html-pdf. I just did a npm link html-pdf that resulted in d:\nodejs\html-pdf -> d:\nodejs\node_modules\html-pdf\bin\index.js > [email protected] install d:\nodejs\node_modules\html-pdf\node_modules\phantomjs-prebuilt > node install.js PhantomJS not found on PATH Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-windows.zip Saving to C:\Users\vijaya.m\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip Receiving... [========================================] 99% Received 17767K total. Extracting zip contents Removing D:\nvm\v6.14.4\node_modules\html-pdf\node_modules\phantomjs-prebuilt\lib\phantom Copying 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\phantom Writing location.js file Done. Phantomjs binary available at D:\nvm\v6.14.4\node_modules\html-pdf\node_modules\phantomjs-prebuilt\lib\phantom\bin\phantomjs.exe + [email protected] added 82 packages from 77 contributors in 79.333s

And pdf.create(...) works good now.

This one helps me too. Thanks a ton @VijayakumarManickam

md-abdul-halim-rafi avatar Feb 04 '21 09:02 md-abdul-halim-rafi

In html-pdf option, we have a property phantomPath: `// File options "type": "pdf", // allowed file types: png, jpeg, pdf "quality": "75", // only used for types png & jpeg

// Script options "phantomPath": "./node_modules/phantomjs/bin/phantomjs", // PhantomJS binary which should get downloaded automatically "phantomArgs": [], // array of strings used as phantomjs args e.g. ["--ignore-ssl-errors=yes"] "localUrlAccess": false, // Prevent local file:// access by passing '--local-url-access=false' to phantomjs ` Ubuntu server cannot found phantom from node-modules so I had to install phantomjs by the script and pass the path '/usr/local/bin/phantomjs' to that option. It worked for me, very crazy issue.

The script to run in Docker file: 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 && \ curl -k -Ls https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 | tar -jxf - &&\ cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs && \ rm -fR phantomjs-2.1.1-linux-x86_64 && \ apk del curl

xoapit avatar May 10 '21 16:05 xoapit

In options of pdf.create(html,options) add below : "phantomPath": "./node_modules/phantomjs-prebuilt/bin/phantomjs", .

Notice I am mentioned phantomjs-prebuilt & not default phantomjs.

I was able to run thie library by above methods on all devices without any global installations.

mir1198yusuf avatar Mar 25 '22 13:03 mir1198yusuf

Very thanks this solution work for me in serverless.

My steps were:

$ npm install phantomjs-prebuilt

pdf.create(html,{ "phantomPath": "./node_modules/phantomjs-prebuilt/bin/phantomjs" });

Then 🚀

scristian9 avatar Apr 06 '22 17:04 scristian9

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

ladaniavadh avatar May 17 '22 13:05 ladaniavadh

This is how I resolved mine. I performed an upgrade on my Docker node, transitioning from node:16.15.0-slim to node:20.5.0. It's working perfectly now.

czarjulius avatar Aug 10 '23 07:08 czarjulius

In options of pdf.create(html,options) add below : "phantomPath": "./node_modules/phantomjs-prebuilt/bin/phantomjs", .

Notice I am mentioned phantomjs-prebuilt & not default phantomjs.

I was able to run thie library by above methods on all devices without any global installations.

This was it for me although phantomPath: "./node_modules/phantomjs-prebuilt/bin/phantomjs"

hypo-thesis avatar Aug 11 '23 21:08 hypo-thesis