Skip to content

fix: add dual build support for ESM and CommonJS#61

Open
condorheroblog wants to merge 3 commits into
curvenote:mainfrom
condorheroblog:main
Open

fix: add dual build support for ESM and CommonJS#61
condorheroblog wants to merge 3 commits into
curvenote:mainfrom
condorheroblog:main

Conversation

@condorheroblog
Copy link
Copy Markdown
Contributor

Reopen #56

@kinecology
Copy link
Copy Markdown

I opened a project that was working back in January, and it wouldn't build, so I had to patch it:
based on this:
https://publint.dev/prosemirror-docx@0.6.1
I added this patch:

diff --git a/node_modules/prosemirror-docx/package.json b/node_modules/prosemirror-docx/package.json
index d10c9d8..1e33dfb 100644
--- a/node_modules/prosemirror-docx/package.json
+++ b/node_modules/prosemirror-docx/package.json
@@ -2,6 +2,12 @@
   "name": "prosemirror-docx",
   "version": "0.6.1",
   "type": "module",
+  "exports": {
+    ".": {
+      "import": "./dist/esm/index.js",
+      "require": "./dist/cjs/index.js"
+    }
+  },

and then ran npx patch-package prosemirror-docx to get it to build.

Only, now, when I export I get an empty file, just like you describe here: #56 (comment)

I tried both of these:

             writeDocx(wordDocument).then((buffer: any) => {
                        const blob = new Blob([buffer]);
                        fileSave(blob, {
                            fileName: "Journal_Export.docx",
                            extensions: ['.docx'],
                        }).then(() => {
                            console.log("saved docx.");
                        });
                    });

and my original

                    writeDocx(wordDocument, (buffer: any) => {
                        const blob = new Blob([buffer]);
                        fileSave(blob, {
                            fileName: "Journal_Export.docx",
                            extensions: ['.docx'],
                        }).then(() => {
                            console.log("saved docx.");
                        });
            
                    });

In both cases, no errors are generated, but the .docx file is empty.

Any ideas why this is happening?

Thanks.

@kinecology kinecology mentioned this pull request Jul 27, 2025
@condorheroblog
Copy link
Copy Markdown
Contributor Author

Hi @kinecology,

I tested it before and found that this PR(https://github.com/curvenote/prosemirror-docx/pull/53/files) caused the problem.

You can use version 0.4.1.

@kinecology
Copy link
Copy Markdown

kinecology commented Jul 27, 2025

Thanks @condorheroblog , so, use 0.4.1 for now, but after you merge this, probably my problem will be fixed, correct?

@condorheroblog
Copy link
Copy Markdown
Contributor Author

No, I just reminded @dan-cooke that his PR had this problem, but I didn't make any fixes for his PR, and he didn't make any commits to fix it, so before this problem is fixed, versions after 0.4.1 will have this problem😂.

@kinecology
Copy link
Copy Markdown

kinecology commented Jul 27, 2025

Ok. I just reverted to 0.4.1, and now it exports the text to the docx, but any images are missing. It was working with images before; like I say, my code was working in January. Do you think maybe a version slightly newer than 0.4.1 might work?

(Below, the ctx etc is coming from a Milkdown editor running in a Svelte component:

            theEditor.saveDocx = async () => {

                let imgBufferMap : Map<string, Buffer> = await noteAttachments.getAllImageBuffersMap(); 
            
                 console.log("imgBuffers ~", imgBufferMap); // I can see the image data

                editor.action((ctx) => {
                 
                    const state = ctx.get(editorStateCtx)

                    const opts: any = {
                        getImageBuffer(src: string)  {
                            return imgBufferMap.get(src);
                        },
                    };

                    const wordDocument = defaultDocxSerializer.serialize(state.doc, opts);
               
                    writeDocx(wordDocument, (buffer: any) => {
                        const blob = new Blob([buffer]);
                        fileSave(blob, {
                            fileName: "Journal_Export.docx",
                            extensions: ['.docx'],
                        }).then(() => {
                            console.log("saved docx.");
                        });

                    });
                });
            };

@condorheroblog
Copy link
Copy Markdown
Contributor Author

@kinecology I think you can delete all the changes involved in PR (https://github.com/curvenote/prosemirror-docx/pull/53/files), do not use it through npm, and directly copy the files of this library to the local project.

Before the problem is solved, I think this solution is feasible😂.

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

Successfully merging this pull request may close these issues.

2 participants