0

I'm trying to use filepreview to get image from a docx document. I've installed it via npm install filepreview.

My example is:

const filepreview = require('filepreview');

filepreview.generate('/input.docx', '/output.gif', (err) => {
    if (err) throw err;
    console.log('FP');
});

But it throws an error like that:

child_process.js:650
    throw err;
    ^

Error: spawnSync file ENOENT
    at Object.spawnSync (internal/child_process.js:1002:20)
    at spawnSync (child_process.js:614:24)
    at Object.execFileSync (child_process.js:642:13)
    at Object.generate (D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\filepreview\filepreview.js:41:40)
    at Object.<anonymous> (D:\Program Files\nodejs\PalettenzettelGenerator\filepreview.js:4:13)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

I don't know why does it give error.

sundowatch
  • 3,012
  • 3
  • 38
  • 66
  • usually ENOENT is when a file is not being found .... see your code, you are trying to access to '/input.docx', is the path ok or should be './input.docx'? let me know if it exist please in the given path. – Jose Mato Sep 06 '19 at 21:43
  • The input.docx is in the same folder with running js file. I tried path.resolve(__dirname), but nothing has changed – sundowatch Sep 06 '19 at 21:51
  • humm, if it's the same, try to do './input.docx', because the current path is being absolute '/input.docx' and I guess is not the expected behavioouor – Jose Mato Sep 06 '19 at 21:53
  • Just a check: Do u have all the dependencies installed o the system for `filepreview` [listed here](https://www.npmjs.com/package/filepreview) – ambianBeing Sep 06 '19 at 21:55
  • 1
    To debug it without problems you can perform next check: const fs = require('fs'); console.log(fs.existsSync('/input.docx')); if the result is false then the file is not where you think it is – Jose Mato Sep 06 '19 at 21:56
  • Actually, with '/input.docx', it gives false, with './input.docx', result is true. But same error – sundowatch Sep 06 '19 at 22:01
  • @ambianBeing checked and updated again. Same error. – sundowatch Sep 06 '19 at 22:03
  • @ambianBeing actually I've tried to install them via npm. Is it the right way? – sundowatch Sep 06 '19 at 22:23
  • @sundowatch `npm install` is only for `filepreview`. Others are needed on the system ( if u're on Ubuntu/Mint/Linux) via `apt-get` installation like mentioned on repo page not npm. – ambianBeing Sep 06 '19 at 23:48
  • @ambianBeing do you know how to do that in windows? – sundowatch Sep 07 '19 at 06:11
  • And also, there is no error about these packages – sundowatch Sep 07 '19 at 06:14
  • @sundowatch [Error: spawn ENOENT](https://stackoverflow.com/a/27883443/6082280) doesn't really tell alot about origins/where etc. apart from the fact that some resource not found is a typical scenario as mentioned previously. For windows might help: [unoconv](https://docs.moodle.org/31/en/Installing_unoconv#Installing_unoconv_on_Windows) [ffmpeg](https://m.wikihow.com/Install-FFmpeg-on-Windows) [imagemagick](https://imagemagick.org/script/download.php#windows) and curl is shipped by default on windows. – ambianBeing Sep 07 '19 at 12:35
  • I'm using yarn package manager now. I think it's all about MSBuild, but don't know how to fix it – sundowatch Sep 09 '19 at 14:38

1 Answers1

0

Try using the absolute path of the file. If it works, then try using __dirname (check docs here) to fetch the path.

Kousika Ganesan
  • 539
  • 1
  • 6
  • 22
  • Tried `filepreview.generateSync()` ? and also try reinstalling all the other dependency modules (unoconv, ffmpeg, imagemagick, curl). – Kousika Ganesan Sep 07 '19 at 05:25