I'm on 5.0.0rc5. When I try to add a hyperlink to the document, I get the following message (while opening the word document): 'Word found unreadable content in "example (5).docx". Do you want to recover the contents of this document? If you trust the source of this document, click Yes.'
See the stackblitz below, note the versions of docx and file-saver in package.json
https://stackblitz.com/edit/angular-cny1zr?file=src/app/app.component.ts
Am I adding the hyperlinks wrong?
Thanks in advance!
P.s. please excuse my not using a proper bug report template.
Edit, I'm on MacOS by the way
@dolanmiu Is this something that is known and/or being worked on? Otherwise, I'll move on to an alternative solution.
p.s. Great library, awesome work
Hi, I have the same problem:
After adding a link to the document, MS Word can't open it without alert (tested on Windows and macOS):

I used the code from this example:
https://github.com/dolanmiu/docx/blob/master/demo/35-hyperlinks.ts
Package version: 5.0.0rc5
Resulting document example:
https://drive.google.com/file/d/1HlGzCMdbTVUZw2cP24hXgB9BycGkRG0T/
same problem on version: 5.0.0-rc7
new Paragraph({
children: [
document.createHyperlink('https://www.google.com', 'Awesome link')
]
})
Is this the right way to create a link ?
I found the problem
in document.xml.rels my hyperlink as a duplicate id (here rId5) :

i dont know how if it's the hyperlink that as the wrong relationshipsCount or if it's header || footer
but removind those duplicate ids fixes my problem
@Sraleik How did #440 fix it for you?
as said by @ramonmata
It's a hacky fix.
I'm trying to find a better one
but for now modifying the library like that works :
@dolanmiu We could just add some method like lodash's uniqueId which will return unique numbers.
+ import getUniqueId from '../utils/get-unique-id';
- this.linkId = relationshipsCount + 1;
+ this.linkId = getUniqueId();
What do you think about this approach? I can make a PR if the solution is OK for you.
I think this PR does just that, it uses a well known library to generate the unique ID. Only problem is that it includes letters and numbers, but apparently it still works as expected:
https://github.com/dolanmiu/docx/pull/448
I will test it out locally before I merge
Thanks @dolanmiu! You're a lifesaver, really wanted this issue to be fixed
Fixed with #448
Most helpful comment
Hi, I have the same problem:
After adding a link to the document, MS Word can't open it without alert (tested on Windows and macOS):

I used the code from this example:
https://github.com/dolanmiu/docx/blob/master/demo/35-hyperlinks.ts
Package version:
5.0.0rc5Resulting document example:
https://drive.google.com/file/d/1HlGzCMdbTVUZw2cP24hXgB9BycGkRG0T/