Error loading custom javascript module from js XPCOM component - Mozilla

This is a discussion on Error loading custom javascript module from js XPCOM component - Mozilla ; Hi all, I have defined a simple javascript module (mymod.jsm): var EXPORTED_SYMBOLS = ["foo"]; var foo = "bar"; and the chrome manifest has a resource entry: resource mymodules modules/ The module is correctly placed in {addonroot}/modules/mymod.jsm and I can enter ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Error loading custom javascript module from js XPCOM component

  1. Error loading custom javascript module from js XPCOM component

    Hi all,

    I have defined a simple javascript module (mymod.jsm):

    var EXPORTED_SYMBOLS = ["foo"];

    var foo = "bar";

    and the chrome manifest has a resource entry:

    resource mymodules modules/

    The module is correctly placed in {addonroot}/modules/mymod.jsm and I
    can enter resources://mymodules/mymod.jsm in the address bar and the
    file will be loaded as expected. When the component is referenced in
    non-component js code, it loads without error.

    However, when I attempt to use the module in a XPCOM component:

    Components.utils.import("resources://mymodules/mymod.jsm");

    I get an error:

    Error: Component returned failure code: 0x80040111
    (NS_ERROR_NOT_AVAILABLE) [nsIXPCComponents_Utils.import]
    Source file: file:///C:/Projects/MyProjects/myaddon/src/components/mycomponent.js
    Line: 32

    The component does use the XPCOM Utils module, and:

    Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

    Works without error. Does anyone have any ideas what I can look at
    next?

    Thanks,
    Gareth

  2. Re: Error loading custom javascript module from js XPCOM component

    I worked it out after a little bit of thought. The resource alias
    defined in the addon chrome.manifest is not available to the component
    until after it has been loaded.

    So, I delayed importing the javascript module until it is required.
    This way it is loaded at runtime and not when the app is starting.

    Gareth

+ Reply to Thread