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

Cannot read property 'uint8array' of undefined in docxgen.js #102

Closed
contactmatts opened this issue Nov 4, 2014 · 8 comments
Closed

Cannot read property 'uint8array' of undefined in docxgen.js #102

contactmatts opened this issue Nov 4, 2014 · 8 comments
Labels

Comments

@contactmatts
Copy link

When attempting to call loadFromeFile on an instance of the docxgen function, I'm getting the following error:

Error: Uncaught TypeError: Cannot read property 'uint8array' of undefined in https://localhost/scripts/lib/docxgen.js at line 17139

My code is structured like so (note that I've used browserify to create a standalone file where docxgen is the global variable, as suggested in this issue #101 ):

        new docxgen().loadFromFile("tagLooping.docx",{async:true}).success(
        function(doc){
            doc.setTags({
                "first_name": "Hipp",
                "last_name": "Edgar",
                "phone": "0652455478",
                "description": "New Website"
            })
            //set the templateVariables
            doc.applyTags()
            //apply them (replace all occurences of {first_name} by Hipp, ...)
            doc.output()
            //Output the document using Data-URI
        });
    };

The error is occurring in the exports.transformTo method at this line:
var result = transform[inputType]outputType;

In the exports.transformTo method, the outputType parameter is "uint8array", and the input parameter is true. When the exports.getTypeOf(input) method is ran, the value true is not a valid input, so undefined is returned. Thus, transform[undefined]... throws an error.

I've posted a minified version of my compiled code at http://pastebin.com/DUvJ3rM8 (it had to minified, since pastebin has a size limit for non-members)

Let me know if any more information is needed to resolve this issue I'm having.

Thank You,

@edi9999
Copy link
Member

edi9999 commented Nov 4, 2014

Can you please post your whole stacktrace ? That would help.

It seems strange to me because the demos use exactly the same code, the only difference seems to be the browserify command. http://javascript-ninja.fr/docxgenjs/examples/demo.html

@edi9999
Copy link
Member

edi9999 commented Nov 4, 2014

If you don't specifically need the qrcode functionality, I also suggest you to switch to version 1.0. Loading a docx is better written than:

See the new demos : http://javascript-ninja.fr/docxtemplater/v1/examples/demo.html

the new docs : http://docxtemplater.readthedocs.org/en/1.x/goals.html

New readme: https://github.com/edi9999/docxtemplater/tree/1.x

@contactmatts
Copy link
Author

This is the stack trace of the error:

"TypeError: Cannot read property 'uint8array' of undefined
at Object.exports.transformTo (https://localhost/scripts/lib/docxgen.js:17139:38)
at Object.ZipEntries.prepareReader (https://localhost/scripts/lib/docxgen.js:17411:54)
at Object.ZipEntries.load (https://localhost/scripts/lib/docxgen.js:17419:14)
at Object.ZipEntries (https://localhost/scripts/lib/docxgen.js:17244:14)
at Object.module.exports [as load]
at Object.JSZip (https://localhost/scripts/lib/docxgen.js:15608:14)
at DocxGen./js\docxgen.js.module.exports.DocxGen.load (https://localhost/scripts/lib/docxgen.js:110:16)
at https://localhost/scripts/lib/docxgen.js:74:17
at https://localhost/scripts/lib/docxgen.js:13635:11
at XMLHttpRequest.DocUtils.loadHttp.xhrDoc.onreadystatechange (https://localhost/scripts/lib/docxgen.js:13746:18)"

Once I get this working, my goal is to replace/insert an image of the user's signature (captured through other means) into the document. Does that require the qrcode functionality? In v.1 documents (https://github.com/edi9999/docxtemplater/tree/1.x), I clicked on the Replacing Images link, but it didn't take me the the replacing image section.

@edi9999
Copy link
Member

edi9999 commented Nov 4, 2014

Yep you can't replace images in 1.x for now, that will come later when the module system comes out.

I'm looking into your error

@edi9999
Copy link
Member

edi9999 commented Nov 4, 2014

I have been able to replicate the issue when they is no file.

Is they a file named tagLooping.docx in your folder (it should be in the same folder as the html, not the js) ?

If yes, can you check your xhr requests ? (You can see them in the debug tools of chrome or firefox, under the network tab)

@contactmatts
Copy link
Author

The issue was the .docx file was not in the same folder as the HTML page. It may be good to throw a more specific exception if the file cannot be found.

Thank you for your help and your quick response.

@edi9999
Copy link
Member

edi9999 commented Nov 4, 2014

I have just added an error on that particular case so that the next users won't hang on that particular issue

@edi9999
Copy link
Member

edi9999 commented Nov 4, 2014

b5eecfc

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

No branches or pull requests

2 participants