Using Modules in Plugins

58 views
Skip to first unread message

maie...@gmail.com

unread,
Jun 7, 2024, 9:49:48 AMJun 7
to zotero-dev
Hi everyone,

I'm trying to split up a plugin into different modules. But upon importing the necessary functions into the main plugin file like so:

import { myFunction as myFunctionFromModuleOne } from "moduleOne.js";

However, I'm getting the error message:
SyntaxError: import declarations may only appear at top level of a module

I've found quite a bit of answers how modules work in regular HTML, but I don't know how that would apply to Zotero. Does anyone know? How can I import functions from modules?

Best,
Denis

XY Wong

unread,
Jun 7, 2024, 12:26:32 PMJun 7
to zotero-dev
To import your JS modules, you can either call `ChromeUtils.importESModule("chrome://path/to/your/file.mjs")`, or use module bundler like webpack or esbuild to bundle them into one JS file.

maie...@gmail.com

unread,
Jun 17, 2024, 4:35:23 AMJun 17
to zotero-dev
Thanks for the hints. That helps a lot.
Reply all
Reply to author
Forward
0 new messages