I wrote a function which utilizes the PDFKit node library to generate a PDF. Everything worked fine when I tested locally using netlify dev but on deploy I receive the following error during invocation.
{
errorType: “RangeError”,
errorMessage: “Invalid typed array length: 4034658560”,
trace: [
“RangeError: Invalid typed array length: 4034658560”,
" at new Uint8Array ()“,
" at new UnicodeTrie (/var/task/node_modules/unicode-trie/index.js:57:28)”,
" at Object. (/var/task/node_modules/unicode-properties/unicode-properties.cjs.js:139:12)“,
" at Module._compile (internal/modules/cjs/loader.js:955:30)”,
" at Object.Module._extensions…js (internal/modules/cjs/loader.js:991:10)“,
" at Module.load (internal/modules/cjs/loader.js:811:32)”,
" at Function.Module._load (internal/modules/cjs/loader.js:723:14)“,
" at Module.require (internal/modules/cjs/loader.js:848:19)”,
" at require (internal/modules/cjs/helpers.js:74:18)“,
" at Object. (/var/task/node_modules/fontkit/index.js:24:31)”
]
}
Thanks for the prompt reply Perry. The error I provided above comes right from the Netlify function logs and here’s a x-nf-request-id: 2c1d044f-79d7-454b-ac80-ebbbb0ceedb4-3035218
(Also happy to provide the function itself privately if that helps)
I was able to get this function deployed via serverless by adding the following plugins:
serverless-apigw-binary
serverless-apigwy-binary
Both of these assist in adding binary file support to Amazon API Gateway. I’m wondering if there is a similar adjustment I can make via Netlify to make this function work properly?
Thanks for writing in. This is an unusual one. We don’t use AWS API Gateway for our functions, we use our own proxy and the Invoke API. I don’t mind filing an issue if there’s something we need to support, but I don’t know what we need to do in this case for this to work properly. Do you know what those two libraries are doing to get this to work? It’s possible you can replicate it within your function already.
Cheers, I’m curious about it too. According to the docs, these plugins:
“…automates the process of adding binary files support in API Gateway.”
In the case of AWS API Gateway, this is simply a switch on the interface. Not sure what is happening behind the scenes. My guess is the plugin is simply glue for a gap in the already exhaustive serverless configuration schema. Any thoughts about the RangeError itself?
hi @leemartin - thank you for your patience. We are still investigating and talking internally about this. We’ll respond here as soon as we have a definitive response!
I found a github issue that seems related: RangeError: Invalid typed array length · Issue #24097 · nodejs/node · GitHub, which seems to be version specific. Could you try setting a different node runtime verions as mentioned here? You do this by setting an ENV VAR on your site named AWS_LAMBDA_JS_RUNTIME with a nodejs version (like nodejs10.x). Let me know if that works.
I pushed some changes to my functions and manually triggered a deploy but I’m not sure if its actually running on the new version I sent in ENV VAR. Is there a way to check this?
You could try logging out process.version as mentioned in StackOverflow to find out what version of Node you are running on. With regards to PDFkit, I don’t have any other ideas since that error seems to be specific to the length of an Array in one of the dependencies, somehow.
Thanks for the help Dennis. Looks like I’m running the right version. I actually had to comment out the dependencies in order to get the function to run and log the version. This leads me believe one of those is the culprit. I’ll keep hacking on it.