[GH-ISSUE #4582] [BUG]: EPUB not uploading due to trim issue #2914

Closed
opened 2026-02-22 18:31:48 -05:00 by yindo · 6 comments
Owner

Originally created by @n8hk7ts4qh-ai on GitHub (Oct 27, 2025).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/4582

Originally assigned to: @angelplusultra on GitHub.

How are you running AnythingLLM?

Docker (local)

What happened?

Getting this error while uploading an EPUB:

[backend] info: [EncryptionManager] Loaded existing key & salt for encrypting arbitrary data.
C:\Program Files\AnythingLLM\resources\backend\node_modules\xml2js\lib\parser.js:344
throw err;
^

TypeError: ((branch[i].navLabel && branch[i].navLabel.text) || branch[i].navLabel || "").trim is not a function
at EPub.walkNavMap (C:\Program Files\AnythingLLM\resources\backend\node_modules\epub2\lib\epub.js:539:105)
at Parser. (C:\Program Files\AnythingLLM\resources\backend\node_modules\epub2\lib\epub.js:492:37)
at Parser.emit (node:events:519:28)
at SAXParser.onclosetag (C:\Program Files\AnythingLLM\resources\backend\node_modules\xml2js\lib\parser.js:276:26)
at emit (C:\Program Files\AnythingLLM\resources\backend\node_modules\sax\lib\sax.js:631:35)
at emitNode (C:\Program Files\AnythingLLM\resources\backend\node_modules\sax\lib\sax.js:636:5)
at closeTag (C:\Program Files\AnythingLLM\resources\backend\node_modules\sax\lib\sax.js:896:7)
at SAXParser.write (C:\Program Files\AnythingLLM\resources\backend\node_modules\sax\lib\sax.js:1460:13)
at exports.Parser.Parser.parseString (C:\Program Files\AnythingLLM\resources\backend\node_modules\xml2js\lib\parser.js:337:31)
at Parser.parseString (C:\Program Files\AnythingLLM\resources\backend\node_modules\xml2js\lib\parser.js:5:59)
at C:\Program Files\AnythingLLM\resources\backend\node_modules\epub2\lib\epub.js:500:23
at C:\Program Files\AnythingLLM\resources\backend\node_modules\epub2\zipfile.js:29:21
at C:\Program Files\AnythingLLM\resources\backend\node_modules\adm-zip\zipEntry.js:132:33
at InflateRaw. (C:\Program Files\AnythingLLM\resources\backend\node_modules\adm-zip\methods\inflater.js:29:29)
at InflateRaw.emit (node:events:519:28)
at endReadableNT (node:internal/streams/readable:1696:12)

Node.js v20.18.0

modified AnythingLLM\resources\backend\node_modules\epub2\lib\epub.js

at this line
title = (branch[i].navLabel && branch[i].navLabel.text || branch[i].navLabel || "").trim();
like this
title = (String((branch[i].navLabel && branch[i].navLabel.text) || branch[i].navLabel || "")).trim();
restarted and it works

Are there known steps to reproduce?

Try different epubs from public free re source a many will fail

Originally created by @n8hk7ts4qh-ai on GitHub (Oct 27, 2025). Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/4582 Originally assigned to: @angelplusultra on GitHub. ### How are you running AnythingLLM? Docker (local) ### What happened? Getting this error while uploading an EPUB: [backend] info: [EncryptionManager] Loaded existing key & salt for encrypting arbitrary data. C:\Program Files\AnythingLLM\resources\backend\node_modules\xml2js\lib\parser.js:344 throw err; ^ TypeError: ((branch[i].navLabel && branch[i].navLabel.text) || branch[i].navLabel || "").trim is not a function at EPub.walkNavMap (C:\Program Files\AnythingLLM\resources\backend\node_modules\epub2\lib\epub.js:539:105) at Parser.<anonymous> (C:\Program Files\AnythingLLM\resources\backend\node_modules\epub2\lib\epub.js:492:37) at Parser.emit (node:events:519:28) at SAXParser.onclosetag (C:\Program Files\AnythingLLM\resources\backend\node_modules\xml2js\lib\parser.js:276:26) at emit (C:\Program Files\AnythingLLM\resources\backend\node_modules\sax\lib\sax.js:631:35) at emitNode (C:\Program Files\AnythingLLM\resources\backend\node_modules\sax\lib\sax.js:636:5) at closeTag (C:\Program Files\AnythingLLM\resources\backend\node_modules\sax\lib\sax.js:896:7) at SAXParser.write (C:\Program Files\AnythingLLM\resources\backend\node_modules\sax\lib\sax.js:1460:13) at exports.Parser.Parser.parseString (C:\Program Files\AnythingLLM\resources\backend\node_modules\xml2js\lib\parser.js:337:31) at Parser.parseString (C:\Program Files\AnythingLLM\resources\backend\node_modules\xml2js\lib\parser.js:5:59) at C:\Program Files\AnythingLLM\resources\backend\node_modules\epub2\lib\epub.js:500:23 at C:\Program Files\AnythingLLM\resources\backend\node_modules\epub2\zipfile.js:29:21 at C:\Program Files\AnythingLLM\resources\backend\node_modules\adm-zip\zipEntry.js:132:33 at InflateRaw.<anonymous> (C:\Program Files\AnythingLLM\resources\backend\node_modules\adm-zip\methods\inflater.js:29:29) at InflateRaw.emit (node:events:519:28) at endReadableNT (node:internal/streams/readable:1696:12) Node.js v20.18.0 modified AnythingLLM\resources\backend\node_modules\epub2\lib\epub.js at this line title = (branch[i].navLabel && branch[i].navLabel.text || branch[i].navLabel || "").trim(); like this title = (String((branch[i].navLabel && branch[i].navLabel.text) || branch[i].navLabel || "")).trim(); restarted and it works ### Are there known steps to reproduce? Try different epubs from public free re source a many will fail
yindo added the bugcore-team-only labels 2026-02-22 18:31:48 -05:00
yindo closed this issue 2026-02-22 18:31:49 -05:00
Author
Owner

@timothycarambat commented on GitHub (Oct 27, 2025):

Can you link an example file since they are public so we can easily reproduce the issue?

@timothycarambat commented on GitHub (Oct 27, 2025): Can you link an example file since they are public so we can easily reproduce the issue?
Author
Owner

@n8hk7ts4qh-ai commented on GitHub (Oct 28, 2025):

Here. GitHub did not allow me to upload a epub so I renamed it .zip, you can rename it and test it . Best

TrimErrorTest.epub.zip

@n8hk7ts4qh-ai commented on GitHub (Oct 28, 2025): Here. GitHub did not allow me to upload a epub so I renamed it .zip, you can rename it and test it . Best [TrimErrorTest.epub.zip](https://github.com/user-attachments/files/23185433/TrimErrorTest.epub.zip)
Author
Owner

@angelplusultra commented on GitHub (Oct 28, 2025):

@n8hk7ts4qh-ai I wasn’t able to reproduce the error using your EPUB file. I tested both uploading it for embeddings and adding it directly as chat context, and no errors were produced in either case. Could you please share the exact steps to reproduce?

@angelplusultra commented on GitHub (Oct 28, 2025): @n8hk7ts4qh-ai I wasn’t able to reproduce the error using your EPUB file. I tested both uploading it for embeddings and adding it directly as chat context, and no errors were produced in either case. Could you please share **the exact steps to reproduce**?
Author
Owner

@n8hk7ts4qh-ai commented on GitHub (Oct 29, 2025):

2025-10-29 12-03-08.zip

attached a video that reproduce the issue and the fix described in this thread, I hope this helps.
Thank you

@n8hk7ts4qh-ai commented on GitHub (Oct 29, 2025): [2025-10-29 12-03-08.zip](https://github.com/user-attachments/files/23208302/2025-10-29.12-03-08.zip) attached a video that reproduce the issue and the fix described in this thread, I hope this helps. Thank you
Author
Owner

@angelplusultra commented on GitHub (Oct 30, 2025):

@n8hk7ts4qh-ai I was able to reproduce the error you were facing. As you noted, this is an upstream problem with the epub2 library. We'll look into a fix for this. As for now, what you could possibly do is unzip the epub and embed its raw contents (e.g the The_Adventures_of_Huckleberry_Finn.xhtml file). Might not get the best results from this, but it's the best solution I can offer for now.

@angelplusultra commented on GitHub (Oct 30, 2025): @n8hk7ts4qh-ai I was able to reproduce the error you were facing. As you noted, this is an upstream problem with the epub2 library. We'll look into a fix for this. As for now, what you could possibly do is unzip the epub and embed its raw contents (e.g the `The_Adventures_of_Huckleberry_Finn.xhtml` file). Might not get the best results from this, but it's the best solution I can offer for now.
Author
Owner

@n8hk7ts4qh-ai commented on GitHub (Oct 30, 2025):

Thank you. I actually did not check the embedding step yet. I am testing all possible issues of document uploading at the moment. Did you already check if the fix I did on the EPUB.js will make the embedding work? or even with that fix the embed fails?

@n8hk7ts4qh-ai commented on GitHub (Oct 30, 2025): Thank you. I actually did not check the embedding step yet. I am testing all possible issues of document uploading at the moment. Did you already check if the fix I did on the EPUB.js will make the embedding work? or even with that fix the embed fails?
yindo changed title from [BUG]: EPUB not uploading due to trim issue to [GH-ISSUE #4582] [BUG]: EPUB not uploading due to trim issue 2026-06-05 14:49:15 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#2914