Import a module… (Thunderbird Beta)

Hello everyone,

Previously, we could use ‹require› to import a module.

var { require } = Cu.import("resource://gre/modules/commonjs/toolkit/require.js", {});

var mymodule = require("resource://myextension/mymodule.js");

But in Thunderbird Beta,
resource://gre/modules/commonjs/toolkit/require.js
doesn’t seem to exist anymore.

There are two possible replacements, you’ll need to see which one still works for your purpose. There is the devtools loader:

var { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});

And then I found resource://gre/modules/workers/require.js which is usually meant for (Web)Workers. I’d try the devools loader first.

Note that any of these may go away without notice. You might be better off putting a copy of it in your add-on and then loading that with Cu.import().

1 Like

Thanks for the answer.

I hope you won’t remove ‹resource://gre/modules/workers/require.js›. My addon uses a PromiseWorker and needs it to load everything.

Is there any chance that we can use soon by default the long awaited statements import/export?

The removal is not really up to us, as these modules are specific to the Gecko/Firefox Platform. Thunderbird uses this platform, but we have no control over the progression. Note I’m not suggesting these modules will be removed any time soon, just that it is generally possible.

import/export should be available via <script type="module">, but I am not sure it is enabled. You can track some of the module progress in bug 1240072