Spawn ENOENT
I'm having somre troubles to create PDF file.
let html = "<p> HELLO ! </p>";
let OPTIONS = {phantomPath: './node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs'};
pdf.create(html, OPTIONS).toFile('output.pdf', function (err, res) {
if (err){
console.log( "MESSAGE => ", err.message);
console.log( "ERROR => ", err);
}
console.log(res);
});
{ Error: spawn ./node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs ENOENT
at exports._errnoException (util.js:1022:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:359:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawn ./node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs',
path: './node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs',
spawnargs: [ '/usr/src/app/node_modules/html-pdf/lib/scripts/pdf_a4_portrait.js' ] }
Using command-line example worked well.
+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:
- Remove globally installed phantomjs (npm uninstall -g phantomjs)
- Make sure /usr/bin/phantomjs doesnt exist. If it does, delete it.
- Install phantomjs locally in the directory which is mounted on docker
Hope that works for you.
I am getting the same error...
I have tried:
- uninstalling phantomjs globally & installing locally
- npm rebuild phantomjs-prebuilt
- versions of phantomjs-prebuilt 2.1.13 & 2.1.14
- installing tar & bzip2 globally
(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 :
- downloading, installing and extracting phantomjs for windows phantomjs-2.1.1-windows.zip from https://phantomjs.org/download.html.
- giving the path to the phantomjs.exe in my options variable:
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?