Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

868
Visualizações
Error: spawn ENOENT html-pdf nodejs in server

I have a problem when create pdf using html-pdf. In my local running well but in server can't work. my code below:

const fileName = './public/offering/' + dayjs().format('YYYY-MM-DD') + '-' + name[0] + '.pdf';

const htmlToPdfOptions = {
     type: 'PDF',
     height: '1200px',
     width: '816px',
     renderDelay: 2000,
     format: 'Letter',
     phantomPath: require('requireg')('phantomjs-prebuilt').path,
};
pdf.create(file, htmlToPdfOptions).toFile(fileName, async function (err: any, result: any) {
   if (err) return console.log(err, 'xxxxxxxxxxxxxx this error');
   console.log(result)
});

in my docker like this

FROM node:14-alpine

RUN npm install --global pm2

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . .

COPY package*.json ./
COPY . .

RUN npm install && npm run build

RUN npm install -g phantomjs --unsafe-perm

COPY . .

EXPOSE 8500

CMD ["pm2-runtime", "start", "src/index.js"]

Error in server is

Error: spawn /usr/src/app/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs ENOENT
     at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
     at onErrorNT (internal/child_process.js:467:16)
     at processTicksAndRejections (internal/process/task_queues.js:82:21) {
   errno: -2,
   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: [
     '--local-url-access=false',
     '/usr/src/app/node_modules/html-pdf/lib/scripts/pdf_a4_portrait.js'
   ]
 }

Can anyone help me? because I have already tried some solutions on the web but nothing works or anyone can give me reference?. example: Nodejs + PhantomJS in Docker: Error: spawn - ENOENT

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your Dockerfile has some strange copie commands. This should solve your problem

FROM node:14-alpine

RUN npm install --global pm2

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . .

RUN npm install && npm run build

RUN npm install -g phantomjs --unsafe-perm

EXPOSE 8500

CMD ["pm2-runtime", "start", "src/index.js"]

You should also add node_modules to your .dockerignore file.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda