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

patchDocument failing #2321

Open
aylusltd opened this issue Sep 1, 2023 · 6 comments
Open

patchDocument failing #2321

aylusltd opened this issue Sep 1, 2023 · 6 comments

Comments

@aylusltd
Copy link

aylusltd commented Sep 1, 2023

So simple reproduction:

    const f = fs.readFileSync(path, {encoding: null})
    const patchedDoc = await patchDocument(u, patch_opts)

TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received type number (80)

I've confirmed path is valid, and can be opened by the process. console.log(f.length) prints the file length in bytes.

for reference:

const patch_opts:PatchDocumentOptions = { patches: {
                velocity_graph : {
                    type: PatchType.PARAGRAPH,
                    children: [
                        new ImageRun({
                            data: await makeImage({
                                url:`${clientBaseUrl}graph/${companyId}/Velocity`,
                                token_user,
                                expectedWidth: 1000,
                                expectedHeight: 415,
                                expectedTop: 30
                            }
                            ),
                            transformation: {
                                width: 1000,
                                height: 415
                            }
                        })
                    ]
                }

Running on:
Node v18.14.2
Ubuntu 22.04

@aylusltd
Copy link
Author

aylusltd commented Sep 1, 2023

The file is a two line docx. Confirmed it opens in word. Contents is

    This is a demonstration template
    {{velocity_graph}}

No formatting is applied.

@aylusltd
Copy link
Author

aylusltd commented Sep 1, 2023

Should have included:

"node_modules/docx": {
         "version": "8.2.2",
         "resolved": "https://registry.npmjs.org/docx/-/docx-8.2.2.tgz",
         "integrity": "sha512-dWI5WfD/fDCLdjIA7CcDzV/1uyBD+mmr7jDLTUN997hcbPz56E701Kf1EEWdibdH9kk+0tFSmE+C0jTlkRZ7kQ==",
         "dependencies": {
            "@types/node": "^20.3.1",
            "jszip": "^3.10.1",
            "nanoid": "^4.0.2",
            "xml": "^1.0.1",
            "xml-js": "^1.6.8"
         },
         "engines": {
            "node": ">=10"
         }
      },

And since the bug is likely in jszip:

"node_modules/jszip": {
         "version": "3.10.1",
         "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz",
         "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==",
         "dependencies": {
            "lie": "~3.3.0",
            "pako": "~1.0.2",
            "readable-stream": "~2.3.6",
            "setimmediate": "^1.0.5"
         }
      },

@aylusltd
Copy link
Author

aylusltd commented Sep 1, 2023

I was able to create a working local version of patchDocument by replacing JSZip with adm-zip and making some other minor alterations to the files. Unfortunately I can't make a PR with what I have. Will try to do it next week.

@dolanmiu
Copy link
Owner

dolanmiu commented Sep 3, 2023

interesting, does regular document creation work for you? that uses jszip too

@SpraxDev
Copy link

Having some issues in Deno with jszip too (#1578) and adm-zip looks kinda nice.
Maybe replacing the lib can fix both issues? 😄

@aylusltd
Copy link
Author

@dolanmiu dunno, we never actually do that. We started with a word template and had to update. We wound up switching just to straight pdf generation though.

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

3 participants