zxhaaa6 / awesome-unoconv

Node.js wrapper for converting Office files to PDF or HTML
MIT License
11 stars 1 forks source link

Error: spawn unoconv ENOENT #1

Open bramvanhoutte opened 5 years ago

bramvanhoutte commented 5 years ago

I get an error when running my implmentation (in Typescript) of the example code:

const path = require('path')
const unoconv = require('awesome-unoconv')
import * as fs from 'fs'

const sourceFilePath = path.resolve('./test.docx')
const outputFilePath = path.resolve('./myDoc.pdf')

unoconv
  .convert(sourceFilePath, outputFilePath)
  .then((result: any) => {
    console.log(result);
  })
  .catch((err: any) => {
    console.log(err);
  });

I get the following error:

{ Error: spawn unoconv ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:246:19)
    at onErrorNT (internal/child_process.js:421:16)
    at processTicksAndRejections (internal/process/next_tick.js:76:17)
    at process.runNextTicks [as _tickCallback] (internal/process/next_tick.js:51:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:800:11)
    at executeUserCode (internal/bootstrap/node.js:526:15)
    at startMainThreadExecution (internal/bootstrap/node.js:439:3)
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn unoconv',
  path: 'unoconv',
  spawnargs:
   [ '-f',
     'pdf',
     '--stdout',
     'C:\\Users\\beantaxbhou\\Documents\\Development\\powerpoint-to-pdf-converter\\build\\test.docx' ] }

I found that 'ENOENT' means that a file can't be found. All the files are present, so this confuses me. Furthermore, when I run the following command in CMD unoconv -f pdf test.docx it works and creates a .pdf file without any errors. What am I missing here?

thisromantelecom commented 5 years ago

I get an error when running my implmentation (in Typescript) of the example code:

const path = require('path')
const unoconv = require('awesome-unoconv')
import * as fs from 'fs'

const sourceFilePath = path.resolve('./test.docx')
const outputFilePath = path.resolve('./myDoc.pdf')

unoconv
  .convert(sourceFilePath, outputFilePath)
  .then((result: any) => {
    console.log(result);
  })
  .catch((err: any) => {
    console.log(err);
  });

I get the following error:

{ Error: spawn unoconv ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:246:19)
    at onErrorNT (internal/child_process.js:421:16)
    at processTicksAndRejections (internal/process/next_tick.js:76:17)
    at process.runNextTicks [as _tickCallback] (internal/process/next_tick.js:51:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:800:11)
    at executeUserCode (internal/bootstrap/node.js:526:15)
    at startMainThreadExecution (internal/bootstrap/node.js:439:3)
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn unoconv',
  path: 'unoconv',
  spawnargs:
   [ '-f',
     'pdf',
     '--stdout',
     'C:\\Users\\beantaxbhou\\Documents\\Development\\powerpoint-to-pdf-converter\\build\\test.docx' ] }

I found that 'ENOENT' means that a file can't be found. All the files are present, so this confuses me. Furthermore, when I run the following command in CMD unoconv -f pdf test.docx it works and creates a .pdf file without any errors. What am I missing here?

unoconv command not found in System paths

weihsth commented 4 years ago

I have the same issue. I downloaded "unoconv-0.8.2" zip, and unpacked it to "C:\dev\unoconv-0.8.2". Windows 10 "Path" Variable ends with ";D:\Libre Office\program\;C:\dev\unoconv-0.8.2\;"

But "awesome-unoconf" still throws error:

unoconv command not found { Error: spawn unoconv ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19) at onErrorNT (internal/child_process.js:415:16) at process._tickCallback (internal/process/next_tick.js:63:19) errno: 'ENOENT', code: 'ENOENT', syscall: 'spawn unoconv', path: 'unoconv', spawnargs: [ '-f', 'pdf', '--stdout', 'C:\solutions\up2boat-api\output.docx' ] }

Zigonja commented 4 years ago

Same issue here

vik17ag commented 4 years ago

same issue

suthishan commented 2 years ago

same issue

unoconv command not found Error: spawn unoconv ENOENT at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19) at onErrorNT (node:internal/child_process:477:16) at processTicksAndRejections (node:internal/process/task_queues:83:21) { errno: -4058, code: 'ENOENT', syscall: 'spawn unoconv', path: 'unoconv',

jovi920204 commented 8 months ago

Hi everyone,

I'm encountering an error and I'm not entirely sure what caused it. However, I've found a solution that might work for you too.

Firstly, I downloaded the unoconv.zip package from github.com/unoconv/unoconv and the latest version of LibreOffice from the LibreOffice website.

Secondly, I unzipped the unoconv.zip file wherever I preferred. In my case, I unzipped it to C:/Program Files (x86)/. It's worth noting that my operating system is Windows 10.

Thirdly, ensure that you can use the unoconv command normally by running python C:/Program Files (x86)/unoconv/unoconv -h. This command should display the usage of unoconv.

Finally, you need to modify the awesome-unoconv package. In the example code provided:

const path = require('path');
const unoconv = require('awesome-unoconv');

const sourceFilePath = path.resolve('./myDoc.docx');
const outputFilePath = path.resolve('./myDoc.pdf');

unoconv
  .convert(sourceFilePath, outputFilePath)
  .then(result => {
    console.log(result); // return outputFilePath
  })
  .catch(err => {
    console.log(err);
  });

Follow the unoconv.convert() function to convert.js. At lines 105 and 134, you need to add {shell: true}. Original code: var unoconv = (0, _child_process.spawn)('unoconv', ['-f', option.format, '--stdout', input]) After modification: var unoconv = (0, _child_process.spawn)('unoconv', ['-f', option.format, '--stdout', input, {shell: true}])

Additionally, we need to change the command unoconv. final code: var unoconv = (0, _child_process.spawn)('python "C:\\Program Files (x86)\\unoconv\\unoconv"', ['-f', option.format, '--stdout', input, {shell: true}])

This solution worked for me. However, I believe there might be better debugging approaches available. Please feel free to communicate with me if you have any suggestions or if you encounter any issues.