node-unoconv icon indicating copy to clipboard operation
node-unoconv copied to clipboard

TypeError: options argument must be an object

Open DevinCarl opened this issue 9 years ago • 4 comments

var unoconv = require('unoconv'); unoconv.convert('1.docx', 'pdf', function (err, result) { // result is returned as a Buffer fs.writeFile('converted.pdf', result); });

below error:

child_process.js:961 throw new TypeError('options argument must be an object'); ^ TypeError: options argument must be an object at normalizeSpawnArguments (child_process.js:961:11) at Object.exports.spawn (child_process.js:984:38) at Object.unoconv.convert (E:\Projects\node_modules\unoconv\index.js:46:26) at Object. (E:\Projects\01_Tmp\hwcloud\test.js:15:9) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Function.Module.runMain (module.js:501:10) at startup (node.js:129:16)

DevinCarl avatar Jul 28 '15 09:07 DevinCarl

The issue is with childProcess.spawn. Using node 0.10.36 should fix your issue. If you can't use an older version try using childProcess.exec(bin, function (err, stdout, stderr) { });

HAASLEWER avatar Jul 28 '15 10:07 HAASLEWER

It seems like .spawn has changed slightly and no longer has the option for a callback. if you remove the callback function from the unoconv.convert function so it looks something like this:

child = childProcess.spawn(bin, args);

child.stdout.on('data', function (data) {
    stdout.push(data);
});

child.stderr.on('data', function (data) {
    stderr.push(data);
});

child.on('exit', function () {
    if (stderr.length) {
        return callback(new Error(Buffer.concat(stderr).toString()));
    }

It worked for me!

aeastes avatar Aug 10 '15 03:08 aeastes

aeastes is correct. I created a new version of this library a few days ago that uses the new version of childProcess.spawn. You can check it out here: https://github.com/HAASLEWER/unoconv2 and https://www.npmjs.com/package/unoconv2 on npm.

HAASLEWER avatar Aug 10 '15 04:08 HAASLEWER

hello !! result is returned as a Buffer fs.writeFile('converted.pdf', result); result is undefined can you help solution this bug

HiXiaolin avatar Feb 21 '17 06:02 HiXiaolin