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.

TypeError: Cannot read properties of undefined (reading 'type')

See original GitHub issue

Hello, I am trying to use html2docx for a react project. But for some reason it keeps crashing with the error: TypeError: Cannot read properties of undefined (reading ‘type’)

I have tried it with the example and then changed it. Both codes yield the same error.

var html = `<html lang="en">
                      <head>
                        <meta charset="UTF-8" />
                        <title>Document</title>
                      </head>
                    <body>` +
                    data +
                    `
                    </body>
                  </html>`;
 HTMLtoDOCX(data, null, {
                    table: { row: { cantSplit: true } },
                    footer: true,
                    pageNumber: true,
                  })
                    .then((fileBuffer) => {
                      fs.writeFile("./document.docx", fileBuffer, (error) => {
                        if (error) {
                          console.log("Docx file creation failed");
                          return;
                        }
                        console.log("Docx file created successfully");
                      });
                    })
                    .catch((err) => {
                      alert(err);
               });

This is my rendition of the code.

My enviroment:

macOS: 12.0 Beta package version: 1.2.4 node version: v16.3.0

Thank you

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
privateOmegacommented, Sep 22, 2021

@zees98 No worries, Its quite unlikely that the package failed with that html string because I am able to generate it without any issue on my laptop with react-example in the examples/ in this repo.

Could you please let me know what’s the end result after clone this repository, and run the example and try it out? I am super curious about this issue.

html-to-docx.docx

0reactions
privateOmegacommented, Sep 23, 2021

@zees98 I might possibly have figured out the issue, please follow the step in the other issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot Read Property of Undefined in JavaScript - Rollbar
The TypeError: Cannot read property of undefined is one of the most common type errors in JavaScript. It occurs when a property is...
Read more >
Uncaught TypeError: Cannot read property of undefined In
JavaScript TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or...
Read more >
TypeError: Cannot read properties of undefined (reading 'and')
It keeps failing with this error in Karma. TypeError: Cannot read properties of undefined (reading 'and') import { ComponentFixture, TestBed } ...
Read more >
[Solved] Cannot read Properties of Undefined in JavaScript
The "Cannot read properties of undefined" error occurs when you try to access a property or a method on a variable that stores...
Read more >
Uncaught TypeError : Cannot read properties of undefined
The solution to TypeError: Cannot read properties of undefined ... The root cause of the error is that the declared variable doesn't have...
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