Error deploying to Vercel / AWS Lambda
See original GitHub issueIn my PC (Kubuntu 20.04) it works perfectly. The problem appears when I deploy to Vercel. To begin with, I need to set phantomPath
, otherwise I get a “write EPIPE” error:
pdf.create(html, {
phantomPath: path.resolve(
process.cwd(),
"node_modules/phantomjs-prebuilt/bin/phantomjs"
),
})
Now, if I run it, it throws:
html-pdf: Received the exit code '1'
Error executing phantom at /var/task/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
Error: spawn /var/task/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
events.js:287
throw er; // Unhandled 'error' event
^
Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:399:19)
at writeOrBuffer (_stream_writable.js:387:5)
at Socket.Writable.write (_stream_writable.js:318:11)
at Socket.ondata (_stream_readable.js:695:22)
at Socket.emit (events.js:310:20)
at addChunk (_stream_readable.js:286:12)
at readableAddChunk (_stream_readable.js:268:9)
at Socket.Readable.push (_stream_readable.js:209:10)
at Pipe.onStreamRead (internal/stream_base_commons.js:186:23)
Emitted 'error' event on Socket instance at:
at errorOrDestroy (internal/streams/destroy.js:108:12)
at Socket.onerror (_stream_readable.js:729:7)
at Socket.emit (events.js:310:20)
at errorOrDestroy (internal/streams/destroy.js:108:12)
at onwriteError (_stream_writable.js:418:5)
at onwrite (_stream_writable.js:445:5)
at doWrite (_stream_writable.js:399:11)
at writeOrBuffer (_stream_writable.js:387:5)
at Socket.Writable.write (_stream_writable.js:318:11)
at Socket.ondata (_stream_readable.js:695:22) {
code: 'ERR_STREAM_DESTROYED'
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:26
Top Results From Across the Web
Why does my Serverless Function work locally but not ...
One of the common reasons for different behavior across environments is whether or not your Serverless Functions depend on packages with native dependencies....
Read more >Deployment on AWS Lambda gives Code 500 Internal ...
I worked on it and got Lambda deployments working now but I feel like my implementation is a bit hacky. :/ I mean...
Read more >Bug with next-i18next and deployment on vercel (recently)
We noticed this bug for the first time Monday around 14:00 CET and think it is potentially related with a change in the...
Read more >Troubleshoot deployment issues in Lambda
When you deploy updates to your function directly with the Lambda API or with a client such as the AWS CLI, you can...
Read more >How to Deploy an Apollo GraphQL Server with Vercel
... when it comes to the deployment of an Apollo GraphQL server such as AWS Lambda, ... and check the logs of your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I forgot to mention it, but I found a (hacky) solution:
First, you add a
fonts.conf
wherever you have your fonts (remember to change thedir
):Then, you download these libs (the same from here, but in a ZIP) and put them in a folder. I put them in
/bins
.Finally, before you run
pdf.create()
, set these env vars:Dev Mode
If your PDF throws some error in Dev mode, you can set the env vars only in production mode. Like this:
Also, remember to change the
phantomPath
!!!I ended up using puppeteer-- was really straight forward.
Borrowed a little from here https://github.com/vercel/vercel/discussions/4903#discussioncomment-234166