marcbachmann / node-html-pdf

This repo isn't maintained anymore as phantomjs got dreprecated a long time ago. Please migrate to headless chrome/puppeteer.
MIT License
3.55k stars 544 forks source link

Error ENOENT when deploy to staging server #672

Open agamtheos opened 2 years ago

agamtheos commented 2 years ago

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! demo@0.0.0 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 commented 2 years ago

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}
niraj1234567890 commented 2 years ago

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

agamtheos commented 2 years ago

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 commented 2 years ago

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