Open taolabz opened 1 year ago
For anyone coming across this same issue, I fought with it for most of the afternoon. My fix ended up being that I needed to include the crypto
package in my build. html-to-docx uses a package called nanoid to generate unique names for image files in the resulting docx(zip) file. This package was using the crypto
node package to generate the unique id. If it isn't included it hits an error which then returns an empty string for the id every time. I use Vite, so I used the vite-plugin-node-polyfills
plugin. There is an error being thrown due to the crypto package not being available, but the error is being swallowed (not quite sure where). If you used Webpack you likely don't run into this bug, as Webpack includes the necessary Node packages.
To avoid this error with a rise of build systems that don't include these packages html-to-docx could consider adding a check for the crypto
package and issuing a warning to the console if it isn't there, or using a different package to generate unique file names that isn't dependent on the crypto
package. Currently each image gets assigned an incrementing id, it would be pretty trivial to just use that as the unique part of the file name. I'd be happy to submit a PR if you think it would be a good solution @privateOmega
Issue: When there are two or more images in the content, all images will become the last image in downloaded docx file.
Code snippet:
Results:
Environment: Chromium Engine Version 111.0.5563.110 macOS 13.0.1