-
Notifications
You must be signed in to change notification settings - Fork 145
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
Unhandled Rejection (TypeError): Cannot call a class as a function error #92
Comments
Could you please post other details and the code you used? |
Sure. I use the lib to generate a docx document of one of my React components, so I added a button which triggers the following function when clicked:
It was working fine a few days ago, but now the app has started crashing. I don't know if it could be a version issue or something else. |
@SensiateLeo Any chance you added a new element to the page or the html output of renderToStaticMarkup changed significantly? Also which version of html-to-docx do you use ? |
@privateOmega unfortunately no. The page is the same as 1 month before. But recently I updated the project packages and some of the libraries had their version upgraded... could this be a problem? |
@SensiateLeo Yes I guess, but cant say anything for sure, Could you please post the markup string here? |
@SensiateLeo @zees98 I think its possibly an issue with the import because of the loader you are using, could you please console.log(HTMLtoDOCX), I think instead of a function, its getting loaded as a class for some reason. |
Try out the following syntaxes
One of it should work I guess. |
@privateOmega First of all, I really appreciate all the help.
these 2 methods yield the same console.log result. console.log results:
|
@zees98 Can we try |
@zees98 @SensiateLeo are you guys on webpack 5? |
|
i executed npx webpack --version in my project and got this:
|
Update:
But the issue persists. |
@privateOmega First of all, I really appreciate all the help until the moment. As @zees98, I tried all the steps that you suggested but the issue still persists |
I'm also getting the same errors that @zees98 commented before |
@zees98 @SensiateLeo could one of you make a sandbox repo for me also to reproduce this issue? |
Sure, I'm on it. |
@privateOmega @SensiateLeo |
@privateOmega @SensiateLeo I have got the package to work for me! I just removed the conversion code from my front end and added it as an API route to my project's backend. Now it works fine. Here is the server-side route code
This may not be the perfect solution for some cases but I believe my project was the problem here and this workaround does not affect my original use case at all, other than the fact that I primarily wanted to be able to generate files at client side. |
@zees98 I'm so happy that you could make it work by running it in the backend, but then again I wish it was working you for the frontend setup as well. I strongly feel its an import problem due to some loader issue, which is something similar to what I was facing when I was trying to make it work on browsers, for setups without frameworks like react. If one of you has some experience with loaders and could help sort this out, that would be amazing, but kudos nevertheless. |
@privateOmega Thank you so much! |
I did a blanket upgrade modules and it worked
|
Hello! Unfortunately the project I am working on is running into the same issue with production build. We are using react-scripts, checking the webpack version react-scripts is running webpack 4.44.2. I'm wondering @shareefalis when you say you blanket upgraded the modules, where did you do this? |
in package.json, in the dependency section of the npm module, this is what i upgraded in the snippet to get the module working.. I believe there is a loader fix in one of the module which fixed this issue |
I am jumping in, facing the same issue with Webpack 4. From the suggestion from @privateOmega about the module import, I tried this PR but webpack then can't find this library, see my comment in the PR. |
I finally figured it out by looking at which library was using this I found this issue from the library's repo by searching the error message in the issues. In that issue, the library author fixed the error and asked to use See my PR #168. |
Released v1.6.3 which should fix this issue. Sorry guys it took forever. Also whoever followed blanket update of packages, I am guessing you guys werent using images, because that should be broken(generate bad .docx file) if you did that I am guessing. |
@privateOmega installation of 1.6.3 fails on my machine :
1.6.2 wasn't failing. |
@zedtux Yes I am forcing the deps of xmlbuilder2 to be the ones that was basically the fix of 2.1.4 of xmlbuilder2. For you its failing probably because you are on older version of node and npm like npm < 7. I am guessing. Is it possible for you to upgrade npm version? Also 1.6.2 doesnt contain the fix, only 1.6.3 does. |
@privateOmega I'm using Docker, and installing Node 14 (still old) using the Alpine Linux package manager (I just figured out that the I just updated my Docker image in order to install and preserve the
A possible fix could be to use |
Thanks for bearing with me on this and mostly for playing the role of a tester on this. It seems that on installing a package as a dependency package-lock.json is ignored by npm and then that would mean |
@privateOmega the package installation is now working, but the library is raising the error again. |
Any chance you have a look at this last issue @privateOmega please ? |
@zedtux Sorry, not yet. Could you please create a sandbox for this, with your build configuration? I am not able to replicate this at my end. |
@privateOmega I think the issue is that you seem to be using a feature from NPM version 8.3 but I'm using NPM 7. I have checked and so far none of the existing Node versions are shipping with NPM 8.3. I've tested with Node 19. I will try to upgrade the NPM globally and see if it fixes the issue. Update after having install the latest NPM 8 version (8.19.3), I still have the same issue. Update 2 I have updated my "resolutions": {
"@oozcitak/util": "8.3.4",
"@oozcitak/dom": "1.15.6"
},
"overrides": {
"@oozcitak/util": "8.3.4",
"@oozcitak/dom": "1.15.6"
} and now it work for me. |
Hi @privateOmega , |
I was getting this error only in the build version of React and the culprit was xmlbuilder2 library of version 2.1.2 which is a dependency of this package. This specific version is required to render the images in docx file but I think the downside of not being able to download the file altogether is much more momentous. You will need at least 2.1.4 version to get rid of this error. |
See this issue: privateOmega#92
Hello,
I'm using the html-to-docx lib to generate docx documents in one one my React projects and recently I am getting the following error when trying to use the HTMLtoDocx() method:
Apparently it starts on the 'html-to-docx.js:171' file. Any idea of why this is happening?
The text was updated successfully, but these errors were encountered: