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

Spawn ENOENT

Open miller-carvalhaes opened this issue 8 years ago • 54 comments

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.

miller-carvalhaes avatar Feb 06 '17 14:02 miller-carvalhaes

+1 I'm facing the same issue here

yogieputra8 avatar Feb 15 '17 06:02 yogieputra8

+1 Me too facing the same issue. BTW, I am running my application in docker. Is there any special attention needed.

vjsrinath avatar Feb 15 '17 16:02 vjsrinath

+1 Same issue. Also using docker. The same code works fine on Windows.

justinneff avatar Feb 17 '17 17:02 justinneff

@vjsrinath @justinneff try my solution on this thread https://github.com/marcbachmann/node-html-pdf/issues/212#issuecomment-280120314

yogieputra8 avatar Feb 18 '17 04:02 yogieputra8

@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:

  1. Remove globally installed phantomjs (npm uninstall -g phantomjs)
  2. Make sure /usr/bin/phantomjs doesnt exist. If it does, delete it.
  3. Install phantomjs locally in the directory which is mounted on docker

Hope that works for you.

sohel-ahmed-ansari avatar Feb 26 '17 15:02 sohel-ahmed-ansari

I am getting the same error...

I have tried:

  1. uninstalling phantomjs globally & installing locally
  2. npm rebuild phantomjs-prebuilt
  3. versions of phantomjs-prebuilt 2.1.13 & 2.1.14
  4. installing tar & bzip2 globally

(Mac OS X, node 4.6.1, html-pdf 2.1.0, phantomjs-prebuilt 2.1.13)

nastassia7 avatar Mar 14 '17 12:03 nastassia7

Use the following

const phantomPath = require('witch')('phantomjs-prebuilt', 'phantomjs');

pdf.create(options.template, {
    phantomPath: `${phantomPath}`,
    ...
})

JoeChapman avatar Mar 20 '17 14:03 JoeChapman

@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 avatar Mar 25 '17 07:03 vjsrinath

@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 avatar Mar 26 '17 15:03 sohel-ahmed-ansari

@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.

vjsrinath avatar Mar 26 '17 18:03 vjsrinath

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.

kitko112 avatar Oct 17 '17 17:10 kitko112

facing the same issue. command line example has the same error. works great on my dev site. any new fixes?

pepethree avatar Jan 11 '18 20:01 pepethree

Why is this close? what's the official solution?

AlessandroAnnini avatar Apr 04 '18 12:04 AlessandroAnnini

8.7.0-wheezy is the solution!!!

Fabryprog avatar Apr 17 '18 10:04 Fabryprog

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

AlessandroAnnini avatar Apr 17 '18 12:04 AlessandroAnnini

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 /

infinito84 avatar Jul 05 '18 02:07 infinito84

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/*

elvizcacho avatar Aug 30 '18 09:08 elvizcacho

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 avatar Sep 01 '18 17:09 cristin

@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'
};

elvizcacho avatar Sep 02 '18 20:09 elvizcacho

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 avatar Nov 30 '18 20:11 sudeepdk

@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

AlessandroAnnini avatar Dec 02 '18 11:12 AlessandroAnnini

I experienced this situation with the wrong path of

"runtimeExecutable": "/usr/local/bin/phantomjs",

after I correct it, the situation gone.

fzvincent avatar Dec 28 '18 15:12 fzvincent

I was having the exact issue in windows. I solved the problem by :

  1. downloading, installing and extracting phantomjs for windows phantomjs-2.1.1-windows.zip from https://phantomjs.org/download.html.
  2. 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};

lipsakandhei avatar Jul 12 '19 06:07 lipsakandhei

@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"]}}

vijaykondamudi avatar Aug 08 '19 19:08 vijaykondamudi

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 avatar Dec 25 '19 11:12 jerryOkafor

@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

mbarish-me avatar May 06 '20 13:05 mbarish-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

Facing the same issue.

himanshu-alphonso avatar Aug 31 '20 05:08 himanshu-alphonso

@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.

aniruddhasm avatar Sep 04 '20 14:09 aniruddhasm

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.

andhareP avatar Oct 21 '20 08:10 andhareP

@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?

andhareP avatar Oct 22 '20 06:10 andhareP