Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Will this project work in browser? #3

Closed
QQCif opened this issue Jun 28, 2020 · 22 comments
Closed

Will this project work in browser? #3

QQCif opened this issue Jun 28, 2020 · 22 comments
Assignees

Comments

@QQCif
Copy link

QQCif commented Jun 28, 2020

Searched NPM and found this project. Tried in browser but gives me error about fs. Is this project for node only or I miss some settings...

@privateOmega
Copy link
Owner

@QQCif Currently this project was made targeting both Node and Frontend frameworks like React, Vue etc. But I will try to add direct browser support ASAP.

@privateOmega privateOmega self-assigned this Jun 29, 2020
@privateOmega
Copy link
Owner

Working on this under feature/browser-example

@BikashKNayak
Copy link

BikashKNayak commented Aug 11, 2020

I installed this in my react typescript application but gives node js related errors such as
Error: Can't resolve 'child_process' in \node_modules\libtidy-updated\node_modules\detect-libc\lib'

Is there any specific instructions that need to be followed to use this in React.

@anirudh-modi
Copy link

anirudh-modi commented Sep 14, 2020

@privateOmega what will be the state of the branch for the browser support? Can we have this feature of browser support?

@josx
Copy link

josx commented Sep 16, 2020

The problem is:
https://github.com/gagern/node-libtidy dont support browser.

@privateOmega
Copy link
Owner

@BikashKNayak @anirudh-modi Sorry for the late reply, I haven't been following this project as much as I would like to due to other commitments. The problem with implementing this package in browser is exactly like @josx said, I started working on this project with an aim to support both ends of the stack but I had to import node-libtidy into the package which essentially cleans up HTML and only works in node environment. Since I have multiple people interested in this being implemented at browser, I will try to work on the package ASAP, removing node-libtidy dependency and supporting browsers. Anyone who is interested can also take this up.

@privateOmega
Copy link
Owner

Removed the libtidy dependency.

@josx
Copy link

josx commented Oct 7, 2020

great!

@itsmhuang
Copy link

Is there any update on how this can work with browser now?

@tenthousandfiRe
Copy link

I'm interested on how this can work with browser

@evrardts
Copy link

Same here, would love to see it working in the browser. Thanks a lot!

@redbrain
Copy link

+1 for browser support. I'll comment so I'm notified of progress.

@privateOmega
Copy link
Owner

privateOmega commented Oct 28, 2020

Guys, I am delighted to know that people have noticed my very first OSS package, thanks for the following.
But I am extremely sorry that I haven't been able to spend some time to follow up on the issues created in this repo, being quite busy with my work.
All that apart I was able to spend some time to figure out the issue at hand finally and I have good news and bad news.

Good news - Figured out the problematic dependency and removed it in feature/browser-example branch, a minifier plugin called html-minifier was the culprit. And I tested this out in react environment and it seems to work well, except for some white-spacing issue.
Replacement is plain regex as of now. :/

Bad news - In browser, I am getting an error of an import from html-to-vdom is giving me undefined instead of the function it should be returning, but from some googling I am certain that it is due to a circular dependency, which I will try to resolve ASAP and this should be good to ship for browser usage as well.

Cheers

NB: People who want to try out this change in react, I guess for now you could do

Edit:
Some issue is there with this command npm install git://github.com/privateOmega/html-to-docx.git#feature/browser-example
Try yarn add git://github.com/privateOmega/html-to-docx.git#feature/browser-example

@ronanjia
Copy link

hi, @privateOmega, Help please, sorry i just can't get it to work in browser.
i installed the feature/browser-example branch, and only got '/example' and '/node_modules' 2 directories in my 'html-to-docx' package
image

I thought some key files might be lost, so i copied '/src', '/template', 'index.js' into the package folder, just got the same error of Can't resolve 'crypto', 'fs', 'path' when i run from "generateContainer" in index.js
image

So is it possible to use this package in a react or an angular project for browser?

@redbrain
Copy link

hi @ronanjia !
Currently, this project isn't functional in browser, that's why this issue is open. It'll be closed when browser support is released.
Until then, try using another, such as https://github.com/evidenceprime/html-docx-js . Not as good, but browser supported.

@ronanjia
Copy link

hi @ronanjia !
Currently, this project isn't functional in browser, that's why this issue is open. It'll be closed when browser support is released.
Until then, try using another, such as https://github.com/evidenceprime/html-docx-js . Not as good, but browser supported.

Thank you so much for your advice, it really would help!

@privateOmega
Copy link
Owner

Guys, I am extremely sorry about turning a blind eye towards this much requested feature for so long, I was so occupied with other things, that I wasn't able to put in any time on this and get this feature out, but today I did spend some time and it seems like there's some issue that I am facing with npm specifically and not yarn and seems like that was the culprit all along and it was misleading me as well when I last worked on this. I will raise a PR now itself after rebasing the branch and hopefully this should be out with next version release.

@privateOmega
Copy link
Owner

privateOmega commented May 1, 2021

@ronanjia Thanks a lot for posting this, it helped me find that this happens only when you try installing with npm and not yarn. Could you please try with yarn and post the result here?

yarn add https://github.com/privateOmega/html-to-docx.git#feature/browser-example if you are trying directly from git.

or

yarn add file:../html-to-docx if you are trying with cloned repo and when you are on feature/browser-example branch. Please do change the relative path appropriately.

@privateOmega
Copy link
Owner

Finally released a new version which contains the changes for browser support, even though it doesn't have support for direct usage using script tag, but it does work with React, so yay. :D

Closing this issue.

@wnabil
Copy link

wnabil commented Jul 25, 2021

@privateOmega i got Cannot call a class as a function using the latest version 1.2.2 when tsconfig is targeting es5
import * as HTMLtoDOCX from 'html-to-docx'; or import HTMLtoDOCX from 'html-to-docx'; const HTMLtoDOCX = require('html-to-docx'); did not help

the project have to target ES2015 then it will work.

@artemdumanov
Copy link

As a workaround, you can use
// @ts-ignore

@haykeminyan
Copy link

haykeminyan commented Oct 19, 2023

could you check please this error with doc/docx?
ERROR Export type is not supported.
I can't export data into docx... changed es2020 to es2015 and seems no changes. All other types are working except doc/docx(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests