Create new tiddlywiki plugin depending on nodejs modules

80 views
Skip to first unread message

Zaibot Slessew

unread,
Oct 1, 2018, 11:29:26 AM10/1/18
to TiddlyWiki
Hi everyone,

I'm trying to create a new tiddlywiki plugin (a syncadaptor for a postgres database). That plugin depends on the nodejs module pg (for database connections), so I've installed pg via npm. The package is located in a folder named node_modules in the top folder TiddlyWiki5. I can successfully build an index.html file, but whenever I load that file I get the following error message:

Error executing boot module $:/plugins/tiddlywiki/adapost/adapost.js: "Cannot find module named 'pg' required by module '$:/plugins/tiddlywiki/adapost/adapost.js', resolved to pg"

What do I have to do to include the npm module pg in my distribution of TiddlyWiki5? Is there an easy way to achive this? It seems like the module has quite a bunch of dependencies and several .js files included.

Thank for your suggestions!

Jed Carty

unread,
Oct 1, 2018, 11:57:49 AM10/1/18
to TiddlyWiki
TiddlyWiki doesn't have a mechanism to include npm modules from the node modules folder. If you use the node version and the modules are used server-side than it can work but packaging them into the single html file version takes a bit more work.

The largest concern with a lot of npm modules is if they can be used by a browser or not, but assuming so than the easiest way is to include them with tiddlywiki.files files. There are a few examples of this in some of the plugins in the GitHub repo, one example is here: https://github.com/Jermolene/TiddlyWiki5/tree/master/plugins/tiddlywiki/jszip/files

an explanation of what .files files do is on tiddlywiki.com here https://tiddlywiki.com/#tiddlywiki.files%20Files

One problem that I have run into with some modules is when they have relative paths in a require, in that case you may have to do some extensive re-writes to make anything work.

Zaibot Slessew

unread,
Oct 1, 2018, 2:25:04 PM10/1/18
to TiddlyWiki
Thanks for your reply.

My fear was that I was only able to import stuff using a tiddlywiki.files file. Thanks also for your link describing what these files do. I wasn't aware of this. Anyway, I'll have to figure out if it is worth trying to pack the required modules in a seperate tiddlywiki.files plugin.
Reply all
Reply to author
Forward
0 new messages