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

Error ENOENT when deploy to staging server

Open agamtheos opened this issue 2 years ago • 4 comments

It was work properly in my local, but when it deploy to the staging server, the buffer result is undefined. And make errors my app. here's my code :

pdf.create(data, options = { type: 'png', quality: '100', orientation: 'portrait', phantomPath: './node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs' } ).toBuffer(function (err, buffer) {
            console.log(buffer)
            const dimension = sizeOf(buffer);
            height = dimension.height;

and this is the error log =

undefined
4/18/2022 4:33:24 PM/app/node_modules/image-size/dist/index.js:113
4/18/2022 4:33:24 PM        throw new TypeError('invalid invocation. input should be a Buffer');
4/18/2022 4:33:24 PM        ^
4/18/2022 4:33:24 PM
4/18/2022 4:33:24 PMTypeError: invalid invocation. input should be a Buffer
4/18/2022 4:33:24 PM    at imageSize (/app/node_modules/image-size/dist/index.js:113:15)
4/18/2022 4:33:24 PM    at /app/helpers/generates.js:874:31
4/18/2022 4:33:24 PM    at execPdfToBuffer (/app/node_modules/html-pdf/lib/pdf.js:47:21)
4/18/2022 4:33:24 PM    at respond (/app/node_modules/html-pdf/lib/pdf.js:141:14)
4/18/2022 4:33:24 PM    at ChildProcess.onError (/app/node_modules/html-pdf/lib/pdf.js:149:46)
4/18/2022 4:33:24 PM    at ChildProcess.emit (events.js:400:28)
4/18/2022 4:33:24 PM    at Process.ChildProcess._handle.onexit (internal/child_process.js:280:12)
4/18/2022 4:33:24 PM    at onErrorNT (internal/child_process.js:469:16)
4/18/2022 4:33:24 PM    at processTicksAndRejections (internal/process/task_queues.js:82:21)
4/18/2022 4:33:24 PMnpm ERR! code ELIFECYCLE
4/18/2022 4:33:24 PMnpm ERR! errno 1
4/18/2022 4:33:24 PMnpm ERR! [email protected] start-worker: `node worker.js`
4/18/2022 4:33:24 PMnpm ERR! Exit status 1
4/18/2022 4:33:24 PMnpm ERR!

How to solve that problem ?

agamtheos avatar Apr 18 '22 09:04 agamtheos

I update my error like this =

Error: spawn ./node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs ENOENT
4/18/2022 4:45:55 PM    at Process.ChildProcess._handle.onexit (internal/child_process.js:274:19)
4/18/2022 4:45:55 PM    at onErrorNT (internal/child_process.js:469:16)
4/18/2022 4:45:55 PM    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
4/18/2022 4:45:55 PM  errno: -2,
4/18/2022 4:45:55 PM  code: 'ENOENT',
4/18/2022 4:45:55 PM  syscall: 'spawn ./node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs',
4/18/2022 4:45:55 PM  path: './node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs',
4/18/2022 4:45:55 PM  spawnargs: [
4/18/2022 4:45:55 PM    '--local-url-access=false',
4/18/2022 4:45:55 PM    '/app/node_modules/html-pdf/lib/scripts/pdf_a4_portrait.js'
4/18/2022 4:45:55 PM  ]
4/18/2022 4:45:55 PM}

agamtheos avatar Apr 18 '22 09:04 agamtheos

@agamtheos Hey, I am facing the same issue. Did you find the solution to this problem? Thnx

niraj1234567890 avatar May 10 '22 04:05 niraj1234567890

I was add this code to my Dockerfile and it's work

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 echo "" > /tmp/openssl.cnf

agamtheos avatar May 11 '22 09:05 agamtheos

@niraj1234567890 you can see in this issue for more detail https://github.com/marcbachmann/node-html-pdf/issues/563#issuecomment-712852134

agamtheos avatar May 11 '22 09:05 agamtheos