ES2015 modules in Anki cards?

Patrice Peterson's Avatar

Patrice Peterson

31 Jul, 2019 04:32 PM

Hi,

I'm trying to add some Javascript to my cards (pretty much total noob here), and I'd like to use ES6 modules for ease of maintenance. This should work since at least Qt 5.12, and "Help > About" tells me my Anki 2.1.13 is using Qt 5.12.3 and PyQt 5.12.2, which, according to the above-linked comment, should enable ES6 features. Still, modules don't work.

This is the answer template I'm using:

{{answer}}
<script type="module">
  import {say} from '_moduletesta.mjs';
  say("42");
</script>

And this is _moduletesta.mjs in my collection.media folder:

export function say(message) {
  console.log(message);
}

I believe this should print 42 to the attached Chrome debug console, but it does not. Instead, the inlined script appears to be silently ignored.

Edit: Crossposted to Reddit, the Qt forums and to the Qt bug tracker.

Comments are closed, but you can start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac