I’m using modern tiddlywiki dev to make my plugin. Often when I import an external library I get an error when running tiddlywiki and I would like to fix it.
In modern I import a library as I would normally in js, and everything compiles together fine. When attempting to run the wiki though I hit this error: TypeError: Cannot read properties of undefined (reading 'navigator')
import { IWidgetEvent, Widget } from 'tiddlywiki';
import { widget } from '$:/core/modules/widgets/widget.js';
import * as pdfMake from 'pdfmake/build/pdfmake';
import htmlToPdfmake from 'html-to-pdfmake';
import 'pdfmake/build/vfs_fonts';
class ExportAsPDF extends widget {
render(parent: Element, nextSibling: Element) {
this.computeAttributes();
this.execute();
}
invokeAction(triggeringWidget: Widget, event: IWidgetEvent) {
var tiddlers = this.wiki.filterTiddlers("[all[]]", this);
var html = htmlToPdfmake(`
<div>
<h1>My title</h1>
<p>
This is a sentence with a <strong>bold word</strong>, <em>one in italic</em>,
and <u>one with underline</u>. And finally <a href="https://www.somewhere.com">a link</a>.
</p>
</div>
`)
pdfMake.createPdf(<any>html).download();
console.log(tiddlers);
return true; // Action was invoked
};
}