我正在尝试在Firebase云功能中使用html5-to-pdf来基于数据生成PDF。 My Cloud函数全部在TypeScript中:
import {HTML5ToPDF} from 'html5-to-pdf/lib';
const createPdf = async (html, localPDFFile) => {
const html5ToPDF = new HTML5ToPDF({
inputBody: html,
outputPath: localPDFFile
});
await html5ToPDF.start();
await html5ToPDF.build();
await html5ToPDF.close();
};
但是当我尝试部署函数时,它给了我以下错误:
Function failed on loading user code. Error message: Code in file lib/index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/node_modules/html5-to-pdf/lib/index.js:79
async start() {
^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/user_code/lib/pdf.js:13:15)
我猜想这与Firebase上的NodeJS版本有关。如果是这样,鉴于我无法更改Firebase的NodeJS版本,是否有任何解决方法?