转换多文件npm包不工作的弹性豆茎亚马逊Linux 2



在成功部署之后,当我运行文档中提到的文件转换脚本时,转换失败了。我的转换脚本

脚本在本地windows 10机器和ubuntu 20.04 lts上完美运行

const { convertWordFiles } = require("convert-multiple-files");
const path = require("path");
async function test() {
try {
const infoOutput = await convertWordFiles(
path.resolve(__dirname, `../../temp/test02.docx`),
"pdf",
path.resolve(__dirname, `../../temp`)
);
} catch (err) {
console.log(err);
}
}
test();

误差我这是

Jul  5 11:30:02 web: /var/app/current/node_modules/convert-multiple-files/lib/utils/instdir/program/soffice.bin: error while loading shared libraries: libxslt.so.1: cannot open 
shared object file: No such file or directory
Jul  5 11:30:02 web: Error: Error converting the file
Jul  5 11:30:02 web: at /var/app/current/node_modules/convert-multiple-files/lib/index.js:68:19
Jul  5 11:30:02 web: at step (/var/app/current/node_modules/convert-multiple-files/lib/index.js:33:23)
Jul  5 11:30:02 web: at Object.next (/var/app/current/node_modules/convert-multiple-files/lib/index.js:14:53)
Jul  5 11:30:02 web: at /var/app/current/node_modules/convert-multiple-files/lib/index.js:8:71
Jul  5 11:30:02 web: at new WrappedPromise (/var/app/current/node_modules/async-listener/es6-wrapped-promise.js:13:18)
Jul  5 11:30:02 web: at __awaiter (/var/app/current/node_modules/convert-multiple-files/lib/index.js:4:12)
Jul  5 11:30:02 web: at convertWordFiles (/var/app/current/node_modules/convert-multiple-files/lib/index.js:44:75)
Jul  5 11:30:02 web: at FileHandlerService.preparePreview (/var/app/current/src/services/fileHandler.js:67:9)
Jul  5 11:30:02 web: at prepareDocumentPreview (/var/app/current/src/subprocess/fileConverter.js:20:60)
Jul  5 11:30:02 web: at async process.<anonymous> (/var/app/current/src/subprocess/fileConverter.js:27:16)
Jul  5 11:30:02 web: Error: Error converting the file
Jul  5 11:30:02 web: at /var/app/current/node_modules/convert-multiple-files/lib/index.js:68:19
Jul  5 11:30:02 web: at step (/var/app/current/node_modules/convert-multiple-files/lib/index.js:33:23)
Jul  5 11:30:02 web: at Object.next (/var/app/current/node_modules/convert-multiple-files/lib/index.js:14:53)
Jul  5 11:30:02 web: at /var/app/current/node_modules/convert-multiple-files/lib/index.js:8:71
Jul  5 11:30:02 web: at new WrappedPromise (/var/app/current/node_modules/async-listener/es6-wrapped-promise.js:13:18)
Jul  5 11:30:02 web: at __awaiter (/var/app/current/node_modules/convert-multiple-files/lib/index.js:4:12)
Jul  5 11:30:02 web: at convertWordFiles (/var/app/current/node_modules/convert-multiple-files/lib/index.js:44:75)
Jul  5 11:30:02 web: at FileHandlerService.preparePreview (/var/app/current/src/services/fileHandler.js:67:9)
Jul  5 11:30:02 web: at prepareDocumentPreview (/var/app/current/src/subprocess/fileConverter.js:20:60)
Jul  5 11:30:02 web: at async process.<anonymous> (/var/app/current/src/subprocess/fileConverter.js:27:16) null

之后,我必须安装两个软件包libxsltlibSM,这部分不再存在了

Jul  5 11:30:02 web: /var/app/current/node_modules/convert-multiple-files/lib/utils/instdir/program/soffice.bin: error while loading shared libraries: libxslt.so.1: cannot open 
shared object file: No such file or directory

表示库已经加载。

但是这次我得到了错误没有任何线索,这是来自下面的行

Jul  5 11:30:02 web: Error: Error converting the file
Jul  5 11:30:02 web: at /var/app/current/node_modules/convert-multiple-files/lib/index.js:68:19

我确实在convert-multiple-files/lib/index.js:68中放置了控制台日志,我得到了以下输出

Error: Command failed: /var/app/current/node_modules/convert-multiple-files/lib/utils/instdir/program/soffice.bin --headless --norestore --invisible --nodefault --nofirststartwizard --nolockcheck --nologo --convert-to pdf --outdir /var/app/current/temp '/var/app/current/temp/test02.docx'
at checkExecSyncError (child_process.js:616:11)
at Object.execSync (child_process.js:652:15)
at /var/app/current/node_modules/convert-multiple-files/lib/index.js:61:31
at step (/var/app/current/node_modules/convert-multiple-files/lib/index.js:33:23)
at Object.next (/var/app/current/node_modules/convert-multiple-files/lib/index.js:14:53)       
at /var/app/current/node_modules/convert-multiple-files/lib/index.js:8:71
at new Promise (<anonymous>)
at __awaiter (/var/app/current/node_modules/convert-multiple-files/lib/index.js:4:12)
at convertWordFiles (/var/app/current/node_modules/convert-multiple-files/lib/index.js:44:75)  
at test (/var/app/current/src/services/converter.js:6:30)
at Object.<anonymous> (/var/app/current/src/services/converter.js:16:1)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
status: 77,
signal: null,
output: [ null, <Buffer >, <Buffer > ],
pid: 4311,
stdout: <Buffer >,
stderr: <Buffer >
}
Error: Error converting the file
at /var/app/current/node_modules/convert-multiple-files/lib/index.js:69:19
at step (/var/app/current/node_modules/convert-multiple-files/lib/index.js:33:23)
at Object.next (/var/app/current/node_modules/convert-multiple-files/lib/index.js:14:53)       
at /var/app/current/node_modules/convert-multiple-files/lib/index.js:8:71
at new Promise (<anonymous>)
at __awaiter (/var/app/current/node_modules/convert-multiple-files/lib/index.js:4:12)
at convertWordFiles (/var/app/current/node_modules/convert-multiple-files/lib/index.js:44:75)  
at test (/var/app/current/src/services/converter.js:6:30)
at Object.<anonymous> (/var/app/current/src/services/converter.js:16:1)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47

这个问题有什么明显的原因吗?还是我遗漏了什么?

所以经过一些调试,我发现这实际上是一个权限问题,我最终为我的弹性豆茎环境编写了一个config文件,文件的内容如下

commands:
01-install_dependencies:
command: sudo yum install libxslt libSM
cwd: /home/ec2-user
02-update_cache:
command: sudo /sbin/ldconfig -v
cwd: /home/ec2-user
03-provide_write_permission_to_convert_multiple_files_lib:
command: sudo chmod -R 777 /var/app/current/node_modules/convert-multiple-files/*
cwd: /home/ec2-user

最新更新