Closed victorfg closed 6 months ago
It seems like it is not finding the executable. Did you try specifying the path to the executable?
Hi @elwerene , you mean that /c/Program Files/LibreOffice/program/soffice
points to the .exe file? How can I do this? Thanks
After adapt my code an call libre.convertWithOptions
the error is the same.
My code now it looks like this:
import libre from "libreoffice-convert";
const fs = require('fs');
const path = require('path')
function convertToPDF(buffer) {
return new Promise((resolve, reject) => {
const options = {
sofficeBinaryPaths: [],
};
const sofficePaths = [
path.join(process.env.PROGRAMFILES, 'LibreOffice\\program\\soffice.exe'),
path.join(process.env.PROGRAMFILESX86, 'LibreOffice\\program\\soffice.exe')
];
// Add the first route valid
for (const p of sofficePaths) {
if (fs.existsSync(p)) {
options.sofficeBinaryPaths.push(p);
break;
}
}
if (options.sofficeBinaryPaths.length === 0) {
console.error('there is no soffice.exe route');
return;
}
libre.convertWithOptions(
buffer,
".pdf",
undefined,
options,
(err, done) => {
if (err) {
console.log("Error converting to PDF:", err);
reject(err);
} else {
console.log("done", done);
resolve(done);
}
}
);
});
}
and the error:
Error in API route: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
at new NodeError (node:internal/errors:399:5)
at validateString (node:internal/validators:163:11)
at Object.join (node:path:429:7)
at eval (webpack-internal:///(api)/./pages/api/excel-to-pdf.js:26:32)
at new Promise (<anonymous>)
at convertToPDF (webpack-internal:///(api)/./pages/api/excel-to-pdf.js:21:10)
at __WEBPACK_DEFAULT_EXPORT__ (webpack-internal:///(api)/./pages/api/excel-to-pdf.js:66:31)
at async Object.apiResolver (C:\Users\alba\Desktop\GUÀRDIES RESIDENTS\guardiesResidents\node_modules\next\dist\server\api-utils\node.js:366:9)
at async DevServer.runApi (C:\Users\alba\Desktop\GUÀRDIES RESIDENTS\guardiesResidents\node_modules\next\dist\server\next-server.js:481:9)
at async Object.fn (C:\Users\alba\Desktop\GUÀRDIES RESIDENTS\guardiesResidents\node_modules\next\dist\server\next-server.js:741:37)
at async Router.execute (C:\Users\alba\Desktop\GUÀRDIES RESIDENTS\guardiesResidents\node_modules\next\dist\server\router.js:252:36)
at async DevServer.run (C:\Users\alba\Desktop\GUÀRDIES RESIDENTS\guardiesResidents\node_modules\next\dist\server\base-server.js:365:29)
at async DevServer.run (C:\Users\alba\Desktop\GUÀRDIES RESIDENTS\guardiesResidents\node_modules\next\dist\server\dev\next-dev-server.js:709:20)
at async DevServer.handleRequest (C:\Users\alba\Desktop\GUÀRDIES RESIDENTS\guardiesResidents\node_modules\next\dist\server\base-server.js:303:20) {
code: 'ERR_INVALID_ARG_TYPE'
}
Any idea how to fix it? Thanks
I'm getting this same error, including after providing the binary path directly to soffice.exe
.
Any suggestions?
Hi,
Im having this error in my application in windows OS:
Error in API route: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined at new NodeError (node:internal/errors:399:5) at validateString (node:internal/validators:163:11) at Object.join (node:path:429:7) at soffice (C:\Users\alba\Desktop\guardiesResidents\node_modules\libreoffice-convert\index.js:25:26) at runTask (C:\Users\alba\Desktop\guardiesResidents\node_modules\async\dist\async.js:1155:17)
which soffice /c/Program Files/LibreOffice/program/soffice
soffice --version LibreOffice 7.6.3.2
I test the same aplication in macOS and it works:
which soffice /opt/homebrew/bin/soffice
soffice --version LibreOffice 7.6.2.1
The error appears in this code: (in libre.convert function)
Thanks