I’m trying to build some functions that return PDFs using PDFkit. I’ve found a few examples for implementing this directly with AWS lambdas but I’m getting the following error when running the functions server with both netlify dev & netlify functions:serve …
Error: ENOENT: no such file or directory, open '/Users/blackcatstudio1/code/ts-pdfgen-lamda/.netlify/functions-serve/pdfgen/src/functions/pdfgen/data.trie'
Object.openSync (fs.js:476:3)
Object.readFileSync (fs.js:377:35)
node_modules/unicode-properties/unicode-properties.cjs.js (/Users/blackcatstudio1/code/ts-pdfgen-lamda/node_modules/unicode-properties/node.js:6:33)
__require (/Users/blackcatstudio1/code/ts-pdfgen-lamda/.netlify/functions-serve/pdfgen/src/functions/pdfgen/index.js:9:44)
node_modules/fontkit/index.js (/Users/blackcatstudio1/code/ts-pdfgen-lamda/.netlify/functions-serve/pdfgen/src/functions/pdfgen/index.js:136732:35)
__require (/Users/blackcatstudio1/code/ts-pdfgen-lamda/.netlify/functions-serve/pdfgen/src/functions/pdfgen/index.js:9:44)
node_modules/pdfkit/js/pdfkit.js (/Users/blackcatstudio1/code/ts-pdfgen-lamda/.netlify/functions-serve/pdfgen/src/functions/pdfgen/index.js:148922:19)
__require (/Users/blackcatstudio1/code/ts-pdfgen-lamda/.netlify/functions-serve/pdfgen/src/functions/pdfgen/index.js:9:44)
Object.<anonymous> (/Users/blackcatstudio1/code/ts-pdfgen-lamda/functions/pdfgen/index.ts:2:25)
Module._compile (internal/modules/cjs/loader.js:1063:30)
Any idea what might be causing this? I have the repo here - it’s the only function in the project currently. Thanks!
The cause is related to UnicodeTrie of which there are two references in the shipped function
var trie = new UnicodeTrie(fs.readFileSync(__dirname + "/data.trie"));
// more ...
var trie = new UnicodeTrie(require("fs").readFileSync(__dirname + "/data.trie"));
There is an issue here though it is related specifically to Webpack, and another here which doesn’t have a solution per se. unicode-trie is dependency of both fontkit and linebreak which are in turn both dependencies of pdfkit. I did try the code from this thread (which the OP appears to have gotten working) with the same result as well as trying this code.
Thank you @mfan and @tomrutgers for chiming in here! This will definitely be beneficial for future forums members who encounter something similar. Happy building
I’m a beginner in netlify function. I got the same error when using pdfkit. please help me to solve this issue.
Error: ENOENT: no such file or directory, open ‘/Users/goutamsamal/Documents/workspace/resume-maker/.netlify/functions-serve/pdf-maker/src/functions/data/Helvetica.afm’
Object.openSync (node:fs:590:3)
Object.readFileSync (node:fs:458:35)
Object.Helvetica (/Users/goutamsamal/Documents/workspace/resume-maker/node_modules/pdfkit/lib/font/standard.js:20:15)
new StandardFont (/Users/goutamsamal/Documents/workspace/resume-maker/node_modules/pdfkit/lib/font/standard.js:60:49)
Function.open (/Users/goutamsamal/Documents/workspace/resume-maker/node_modules/pdfkit/lib/font_factory.js:11:16)
PDFDocument.font (/Users/goutamsamal/Documents/workspace/resume-maker/node_modules/pdfkit/lib/mixins/fonts.js:51:33)
PDFDocument.initFonts (/Users/goutamsamal/Documents/workspace/resume-maker/node_modules/pdfkit/lib/mixins/fonts.js:17:12)
new PDFDocument (/Users/goutamsamal/Documents/workspace/resume-maker/node_modules/pdfkit/lib/document.js:88:10)
/Users/goutamsamal/Documents/workspace/resume-maker/functions/helper/makePdf.js:6:17
new Promise ()