question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught (in promise) TypeError: Cannot read property 'slice' of undefined

See original GitHub issue

when I try generate blob from my document, then TypeError occured

import { pdf } from "@react-pdf/renderer";
import { saveAs } from "file-saver";

const downloadPdf = async () => {
    const blob = await pdf(<Document />).toBlob();  //error here
    saveAs(blob, "document.pdf");
  };

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
cmnstmntmncommented, Jul 10, 2020

@nicholasstephan you may check this workaround for 2.0

import { saveAs } from "file-saver";
import { pdf } from "@react-pdf/renderer";
import { PDFPage } from "./PDFPage";

const generatePDFDocument = async () => {
  const blobPdf = await pdf(PDFPage());
  blobPdf.updateContainer(PDFPage());
  const result = await blobPdf.toBlob();

  saveAs(result, "document.pdf");
};

export default generatePDFDocument;
<button onClick={generatePDFDocument}>Download PDF</button>
2reactions
diegomuracommented, Jul 15, 2020

My bad! I removed the beta version as the latest on npm. I’m aware of this bug on 2.0 and will be fixed for next deploy. Thanks for addressing this!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with error Cannot read property 'slice' of undefined
I faced the same error today, and solved it by initializing the array to an empty array before performing any slice ...
Read more >
TypeError: Cannot read Property 'slice' of Undefined in JS
The "Cannot read property 'slice' of undefined" error occurs when the slice() method is called on an undefined value. To solve the error,...
Read more >
Cannot read property 'slice' of undefined error when trying to ...
Hi guys, As the title says, I am getting a Cannot read property 'slice' of undefined error in the console when trying to...
Read more >
TypeError: Cannot read property 'slice' of undefined - Support
Hello, I encountered the same problem with the new version solc compiler. ... Error: TypeError: Cannot read property 'slice' of undefined at ...
Read more >
TypeError: Cannot read property 'slice' of undefined - MongoDB
So you can not retrieve that token because there is no Header so there is undefined variable. You are trying to slice that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found