html-to-docx icon indicating copy to clipboard operation
html-to-docx copied to clipboard

TypeError: Class extends value undefined is not a constructor or null

Open jenyaftw opened this issue 3 years ago • 5 comments

Error while importing into React project

import HTMLtoDOCX from 'html-to-docx';

const downloadDocument = async () => {
    await saveDocument.mutate();
    const finalHtml = `<!DOCTYPE html><html><body>hello</body></html>`;
    const blob = await HTMLtoDOCX(finalHtml, null, {
      table: { row: { cantSplit: true } },
      footer: true,
      pageNumber: true,
    });
    saveAs(blob, `doc.docx`);
  };
Screenshot 2022-04-13 at 19 04 03

jenyaftw avatar Apr 13 '22 16:04 jenyaftw

Well, do u solved the problem?

zzyouyou avatar Oct 27 '22 09:10 zzyouyou

Same issue here.

arieltoledo avatar Nov 11 '22 14:11 arieltoledo

I also ran into this. Has anyone found a solution?

vonWolfehaus avatar Apr 19 '23 23:04 vonWolfehaus

Same issue on my side. I am using Vue 3.

thiagoarantes avatar May 14 '23 01:05 thiagoarantes

I encountered same problem with Vite + Vue3.

It seems that this package depends on xmlbuilder2.

The error is thrown here: https://github.com/oozcitak/xmlbuilder2/blob/master/src/builder/XMLBuilderCBImpl.ts

export class XMLBuilderCBImpl extends EventEmitter implements XMLBuilderCB 

I'm not really sure what went wrong in the middle, but I eventually solved the problem with this vite plugin(vite-plugin-node-stdlib-browser), there should be a better solution🄲.


My solution:

  1. Install package

    pnpm i -D vite-plugin-node-stdlib-browser
    
  2. Enable plugin in vite.config.ts

    import nodePolyfills from 'vite-plugin-node-stdlib-browser';
    
    export default defineConfig({
        plugins: [
            nodePolyfills()
        ]
    });
    
  3. Rerun the project

CatsJuice avatar Jun 08 '23 02:06 CatsJuice