LT;DR:
A working solution is simply overwriting the file sql.js with sql-memory-growth.js.
Caution: I am not sure whether this replacement will cause any unseen or mysterious side effects to anki-apkg-export, so far, it works smoothly on my device.
Use at your own risk!
Anki is a useful app that helps us to memorise things more effectively. It uses Spaced Repetition algorithms under the hook. Google this for more.
To create Anki decks and notes, we can do them manually or programmatically.
Creating a note manually is also a learning and memorising step, sometimes it is fun too. You can modify and fancy your notes up to your heart consent. In addition, since they are more personalized, or linked to your world, it will help you memorise them easier and longer.
To create many Anki notes programmatically on my phone, I use this node_module: anki-apkg-export, running on Termux.
My device is currently running Android 10, (arm64-v8a), Termux v0.113, Nodejs v14.15.4, anki-apkg-export v4.0.3
# On Termux install Nodejs and npm first, then install anki-apkg-export globally:
npm i -g anki-apkg-export
As the package name suggested, it helps create Anki decks packaged in apkg files. It supports Anki version 2 and runs smoothly for small decks. However, for larger ones, it may yield errors related to memory limit as follows:
...
abort("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value 16777216, (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime but prevents some optimizations, (3) set Module.TOTAL_MEMORY to a higher value before the program runs, or (4) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ")
at Error at jsStackTrace (/data/data/com.termux/files/usr/lib/node_modules/anki-apkg-export/node_modules/sql.js/js/sql.js:3:13718)
at stackTrace (/data/data/com.termux/files/usr/lib/node_modules/anki-apkg-export/node_modules/sql.js/js/sql.js:3:13889)
...
So sql.js is a dependence of anki-apkg-export and the approximate cause of the error. To fix this memory limit issue, I found a working solution mentioned here:
That is simply overwriting the file sql.js with sql-memory-growth.js
Run the below commands on Termux, to backup and overwrite sql.js file. Your installation path on Termux may vary, but the principle should be the same:
cd /data/data/com.termux/files/usr/lib/node_modules/anki-apkg-export/node_modules/sql.js/js
# backup the original file
cp sql.js sql.js_backup
# overwrite
cp sql-memory-growth.js sql.js
Exit Termux or cd back to your working directory, and re-run your code
PS: I also found a suggestion that set
Module = { TOTAL_MEMORY: 536870912 }
to increase the module total memory (read the error message). Unfortunately, it did not work for Termux on my device.