Open miller-carvalhaes opened 7 years ago
+1 I'm facing the same issue here
+1 Me too facing the same issue. BTW, I am running my application in docker. Is there any special attention needed.
+1 Same issue. Also using docker. The same code works fine on Windows.
@vjsrinath @justinneff try my solution on this thread https://github.com/marcbachmann/node-html-pdf/issues/212#issuecomment-280120314
@vjsrinath @justinneff I was facing the same issue in docker. Managed to solve it though. The cause was that i had a global version of phantomjs already installed on my machine. Docker doesnt have access to module installed globally.
Solution:
Hope that works for you.
I am getting the same error...
I have tried:
(Mac OS X, node 4.6.1, html-pdf 2.1.0, phantomjs-prebuilt 2.1.13)
Use the following
const phantomPath = require('witch')('phantomjs-prebuilt', 'phantomjs');
pdf.create(options.template, {
phantomPath: `${phantomPath}`,
...
})
@sohel-ahmed-ansari the issue was happening when i was using the official node image based on alphine linux. Later I created my own image based on ubuntu, it worked. I didn't have to install phantomjs globally. Take a look at my Dockerfile
Thanks
@vjsrinath Didn't get what you mean. I already had global phantomjs installed, which was causing this issue. Had to remove the global version and install locally to solve it
@sohel-ahmed-ansari I think we arrived at an issue from two different places. I was facing this issue in my docker container that was created from node alphine linux image. When i switched the base image to ubuntu it worked for me.
I have this problem when I use 8.7.0-alpin
in my docker file. I got my problem solved just using 8.7.0-wheezy
instead, no source code changes.
facing the same issue. command line example has the same error. works great on my dev site. any new fixes?
Why is this close? what's the official solution?
8.7.0-wheezy
is the solution!!!
ciao! @Fabryprog, tnx but i was facing the same problem as @pepethree i think, or, at least it wasn't working for me.
my solution is now to use node:8.11.1
Hi after searching everywhere I found this workaround that works on docker nodejs based on alpine:
Before npm install or yarn install to put this code: RUN wget -qO- "https://github.com/dustinblackman/phantomized/releases/download/2.1.1a/dockerized-phantomjs.tar.gz" | tar xz -C /
After trying @infinito84 solution and adding some extra dependencies I managed to make it work like this on this image node:8.11.3-alpine:
# Add support for https on wget
RUN apk update && apk add --no-cache wget && apk --no-cache add openssl wget && apk add ca-certificates && update-ca-certificates
# Add phantomjs
RUN wget -qO- "https://github.com/dustinblackman/phantomized/releases/download/2.1.1a/dockerized-phantomjs.tar.gz" | tar xz -C / \
&& npm config set user 0 \
&& npm install -g phantomjs-prebuilt
# Add fonts required by phantomjs to render html correctly
RUN apk add --update ttf-dejavu ttf-droid ttf-freefont ttf-liberation ttf-ubuntu-font-family && rm -rf /var/cache/apk/*
Thank you @elvizcacho for this solution. I can confirm it works when using PhantomJS in Docker.
There is still an issue when attaching a volume to the docker service:
UnhandledPromiseRejectionWarning: Error: spawn Unknown system error -8
Has anybody encountered this issue before?
@cristin Can you elaborate further what are you trying to do? If you are using html-pdf lib you have to set the phantomPath path on the option object to point to the global installed phantomjs as the example below:
const options = {
format: 'Legal',
orientation: 'portrait',
phantomPath: '/usr/local/bin/phantomjs'
};
This will work 100 % -- follow this it worked for me ...
const options = { format: 'Legal', orientation: 'portrait', phantomPath: '/usr/local/bin/phantomjs' };
https://www.vultr.com/docs/how-to-install-phantomjs-on-ubuntu-16-04
@sudeepdk It does not with alpine..
> Step 2/17 : RUN apk --update --no-cache add freetype fontconfig build-essential chrpath libssl-dev libxft-dev libfreetype6-dev libfreetype6 libfontconfig1-dev libfontconfig1 wget
> ---> Running in 3018631de6a1
> fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
> fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
> ERROR: unsatisfiable constraints:
> build-essential (missing):
> required by: world[build-essential]
> libfontconfig1 (missing):
> required by: world[libfontconfig1]
> libfontconfig1-dev (missing):
> required by: world[libfontconfig1-dev]
> libfreetype6 (missing):
> required by: world[libfreetype6]
> libfreetype6-dev (missing):
> required by: world[libfreetype6-dev]
> libssl-dev (missing):
> required by: world[libssl-dev]
> Removing intermediate container 3018631de6a1
I experienced this situation with the wrong path of
"runtimeExecutable": "/usr/local/bin/phantomjs",
after I correct it, the situation gone.
I was having the exact issue in windows. I solved the problem by :
var options = { format: 'A4', "phantomPath": "C:\\Users\\HP\\Downloads\\phantomjs-2.1.1-windows\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe" , type: 'pdf',timeout: 30000};
@Guys - Any help is appreciated. I am seeing this error which downloading PDF {"err":{"errno":"ENOENT","code":"ENOENT","syscall":"spawn /usr/src/app/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs","path":"/usr/src/app/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs","spawnargs":["--ignore-ssl-errors=yes","/usr/src/app/node_modules/html-pdf/lib/scripts/pdf_a4_portrait.js"]}}
After trying @infinito84 solution and adding some extra dependencies I managed to make it work like this on this image node:8.11.3-alpine:
# Add support for https on wget RUN apk update && apk add --no-cache wget && apk --no-cache add openssl wget && apk add ca-certificates && update-ca-certificates # Add phantomjs RUN wget -qO- "https://github.com/dustinblackman/phantomized/releases/download/2.1.1a/dockerized-phantomjs.tar.gz" | tar xz -C / \ && npm config set user 0 \ && npm install -g phantomjs-prebuilt # Add fonts required by phantomjs to render html correctly RUN apk add --update ttf-dejavu ttf-droid ttf-freefont ttf-liberation ttf-ubuntu-font-family && rm -rf /var/cache/apk/*
This one worked for me.
@jerryOkafor @elvizcacho I no longer get the phantomPath error but a new font error
Fontconfig warning: line 5: unknown element "its:rules" Fontconfig warning: line 6: unknown element "its:translateRule"
Any help appreciated
@jerryOkafor @elvizcacho I no longer get the phantomPath error but a new font error
Fontconfig warning: line 5: unknown element "its:rules" Fontconfig warning: line 6: unknown element "its:translateRule"
Any help appreciated
Facing the same issue.
@lipsakandhei I tried what you said but I am getting this error. Error: html-pdf: PDF generation timeout. Phantom.js script did not exit.
const options = {
format: 'A4',
phantomPath: ' C:\\Downloads\\ProjectName\\node_modules\\phantomjs-prebuilt\\lib\\phantom\\bin\\phantomjs.exe',
renderDelay: 'manual'
}
Any assistance is greatly appreciated.
I am facing same issue. Getting -{"errno":"ENOENT","code":"ENOENT","syscall":"spawn /app/node_modules/phantomjs-prebuilt/lib/phantom\bin\phantomjs.exe","path":"/app/node_modules/phantomjs-prebuilt/lib/phantom\bin\phantomjs.exe","spawnargs":["/app/node_modules/html-pdf/lib/scripts/pdf_a4_portrait.js"]
I tried providing phantom path in options too but didn't help in resolving this issue.
Any help is highly appreciated.
@guys - Any help is appreciated. I am seeing this error which downloading PDF {"err":{"errno":"ENOENT","code":"ENOENT","syscall":"spawn /usr/src/app/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs","path":"/usr/src/app/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs","spawnargs":["--ignore-ssl-errors=yes","/usr/src/app/node_modules/html-pdf/lib/scripts/pdf_a4_portrait.js"]}}
Were you able to resolve this issue?
+1 Me too facing the same issue. BTW, I am running my application in docker. Is there any special attention needed.
I am facing same issue while running in docker, how did you fix issue in your case?
After trying @infinito84 solution and adding some extra dependencies I managed to make it work like this on this image node:8.11.3-alpine:
# Add support for https on wget RUN apk update && apk add --no-cache wget && apk --no-cache add openssl wget && apk add ca-certificates && update-ca-certificates # Add phantomjs RUN wget -qO- "https://github.com/dustinblackman/phantomized/releases/download/2.1.1a/dockerized-phantomjs.tar.gz" | tar xz -C / \ && npm config set user 0 \ && npm install -g phantomjs-prebuilt # Add fonts required by phantomjs to render html correctly RUN apk add --update ttf-dejavu ttf-droid ttf-freefont ttf-liberation ttf-ubuntu-font-family && rm -rf /var/cache/apk/*
docker in node:alpin I change
&& npm install -g phantomjs-prebuilt
to
&& npm uninstall -g phantomjs \ && npm install phantomjs
that worked for me. thanks!
Hi after searching everywhere I found this workaround that works on docker nodejs based on alpine:
Before npm install or yarn install to put this code: RUN wget -qO- "https://github.com/dustinblackman/phantomized/releases/download/2.1.1a/dockerized-phantomjs.tar.gz" | tar xz -C /
worked fantastic
Hi after searching everywhere I found this workaround that works on docker nodejs based on alpine:
Before npm install or yarn install to put this code: RUN wget -qO- "https://github.com/dustinblackman/phantomized/releases/download/2.1.1a/dockerized-phantomjs.tar.gz" | tar xz -C /
If you have the same problem with node alphine images, THIS IS THE SOLUTION
- npm uninstall -g phantomjs
didn't worked for me
Use the following
const phantomPath = require('witch')('phantomjs-prebuilt', 'phantomjs'); pdf.create(options.template, { phantomPath: `${phantomPath}`, ... })
I was struggling with this issue since 2 days, many solutions suggesting running phantomjs script inside docker container and uninstalling globally installed one didn't worked either , this one worked. Thanks
this is how it worked for me. Docker file:
FROM node:14-alpine
WORKDIR /app
COPY package.json .
RUN apk update && apk add --no-cache wget && apk --no-cache add openssl wget && apk add ca-certificates && update-ca-certificates
RUN wget -qO- "https://github.com/dustinblackman/phantomized/releases/download/2.1.1a/dockerized-phantomjs.tar.gz" | tar xz -C / \ && npm config set user 0 \ && npm install -g phantomjs-prebuilt
RUN apk add --update ttf-dejavu ttf-droid ttf-freefont ttf-liberation && rm -rf /var/cache/apk/*
RUN npm install
COPY . ./
EXPOSE $PORT
CMD [ "npm","start" ]
this is how it worked for me. Docker file:
@alihasnain1997 Did you add any path in the phantomPath?
this is how it worked for me. Docker file:
@alihasnain1997 Did you add any path in the phantomPath?
@du-camiloj nope didn't added any path
Use the following
const phantomPath = require('witch')('phantomjs-prebuilt', 'phantomjs'); pdf.create(options.template, { phantomPath: `${phantomPath}`, ... })
Hello @JoeChapman
Why this way? In my case the phantomjs-prebuilt
was in the /path/to/project/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
and the file /path/to/project/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
returned:
phantomjs: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.26, BuildID[sha1]=d0f2a21ff9e0b82113a2095e7cbca7dceaba88fb, stripped
Is there anything wrong with my file?
I have this problem when I use
8.7.0-alpin
in my docker file. I got my problem solved just using8.7.0-wheezy
instead, no source code changes.
@kitko112 wheezy has no 16.x images or even 12.x. Did you change the base image again to other linux distros?
phantomPath @mbarish-me Did you try this solution: https://github.com/marcbachmann/node-html-pdf/issues/233#issuecomment-289195523
I face it again. I am confused now
Dockerfile
fixed my issue:FROM node:16.14.0-alpine3.15
WORKDIR /app
COPY package*.json ./
# Add support for https on wget
RUN apk update && apk add --no-cache wget && apk --no-cache add openssl wget && apk add ca-certificates && update-ca-certificates
# Add phantomjs
RUN wget -qO- "https://github.com/dustinblackman/phantomized/releases/download/2.1.1a/dockerized-phantomjs.tar.gz" | tar xz -C / \
&& npm config set user 0 \
&& npm install -g phantomjs-prebuilt
# Add fonts required by phantomjs to render html correctly
RUN apk add --update ttf-dejavu ttf-droid ttf-freefont ttf-liberation && rm -rf /var/cache/apk/*
# see this: https://github.com/marcbachmann/node-html-pdf/issues/563#issuecomment-712852134
RUN echo "" > /tmp/openssl.cnf
RUN npm install
# Rest of your Dockerfile, Instructions like COPY . /
If npm install -g phantomjs-prebuilt
does not work, get rid of this line && npm config set user 0
And that's it, No need to pass phantomPath
option to create
. We finished. I hope this help you. If your problem does not vanished, do not blame yourself. Computers are stupid enough. Nothing is wrong with you. Just try other solutions and give yourself 10 minute untrack. it will help you
Best wishes.
Pain.
This Dockerfile fixed it for me. No need to pass phantomPath
option.
FROM node:12
WORKDIR /var/www
RUN apt-get update && apt-get install -y autoconf autogen libgl1-mesa-glx
# Rest of your Dockerfile, Instructions like COPY . /
With other node versions i got different errors. Good luck.
@kasir-barati thanks for your solution, FYI I also had to add the following in my options for html-pdf
phantomPath: '/usr/local/bin/phantomjs',
From the future
I face it again. I am confused now
This
Dockerfile
fixed my issue:FROM node:16.14.0-alpine3.15 WORKDIR /app COPY package*.json ./ # Add support for https on wget RUN apk update && apk add --no-cache wget && apk --no-cache add openssl wget && apk add ca-certificates && update-ca-certificates # Add phantomjs RUN wget -qO- "https://github.com/dustinblackman/phantomized/releases/download/2.1.1a/dockerized-phantomjs.tar.gz" | tar xz -C / \ && npm config set user 0 \ && npm install -g phantomjs-prebuilt # Add fonts required by phantomjs to render html correctly RUN apk add --update ttf-dejavu ttf-droid ttf-freefont ttf-liberation && rm -rf /var/cache/apk/* # see this: https://github.com/marcbachmann/node-html-pdf/issues/563#issuecomment-712852134 RUN echo "" > /tmp/openssl.cnf RUN npm install # Rest of your Dockerfile, Instructions like COPY . /
Side note:
If
npm install -g phantomjs-prebuilt
does not work, get rid of this line&& npm config set user 0
README fore sure
And that's it, No need to pass
phantomPath
option tocreate
. We finished. I hope this help you. If your problem does not vanished, do not blame yourself. Computers are stupid enough. Nothing is wrong with you. Just try other solutions and give yourself 10 minute untrack. it will help youBest wishes.
Give this man an Oscar
Use the following
const phantomPath = require('witch')('phantomjs-prebuilt', 'phantomjs'); pdf.create(options.template, { phantomPath: `${phantomPath}`, ... })
I was struggling with this issue since 2 days, many solutions suggesting running phantomjs script inside docker container and uninstalling globally installed one didn't worked either , this one worked. Thanks
This worked for me. Thanks :)
From the future
I face it again. I am confused now
This
Dockerfile
fixed my issue:FROM node:16.14.0-alpine3.15 WORKDIR /app COPY package*.json ./ # Add support for https on wget RUN apk update && apk add --no-cache wget && apk --no-cache add openssl wget && apk add ca-certificates && update-ca-certificates # Add phantomjs RUN wget -qO- "https://github.com/dustinblackman/phantomized/releases/download/2.1.1a/dockerized-phantomjs.tar.gz" | tar xz -C / \ && npm config set user 0 \ && npm install -g phantomjs-prebuilt # Add fonts required by phantomjs to render html correctly RUN apk add --update ttf-dejavu ttf-droid ttf-freefont ttf-liberation && rm -rf /var/cache/apk/* # see this: https://github.com/marcbachmann/node-html-pdf/issues/563#issuecomment-712852134 RUN echo "" > /tmp/openssl.cnf RUN npm install # Rest of your Dockerfile, Instructions like COPY . /
Side note:
If
npm install -g phantomjs-prebuilt
does not work, get rid of this line&& npm config set user 0
README fore sure
And that's it, No need to pass
phantomPath
option tocreate
. We finished. I hope this help you. If your problem does not vanished, do not blame yourself. Computers are stupid enough. Nothing is wrong with you. Just try other solutions and give yourself 10 minute untrack. it will help you Best wishes.Give this man an Oscar
From an alternate future (2023) and using the container image: node:16.20-alpine I had to add:
ENV OPENSSL_CONF=/etc/ssl/
before npm install.
Thank you guys! this a lifesaver post.
Thanks @claudrocker, your solution is the only that work for me, for while at least.
@claudrocker
running this script causes npm install to fail any ideas why? I even removed the script and now i cant even build anything and keep getting some error about puppeter
I'm having somre troubles to create PDF file.
Using command-line example worked well.