Question

I am using Mozilla Addon builder (Node.js/common.js) to build a FireFox addon. Please note, I have the files in question (explained later) in the Data-Folder that the builder gives you by default.

In the Data folder (comes by default) I have two files: file1 and file2:

File1

exports.foo = foo;  

functions foo() {
    return true
}

File2

$('#aTestButton').click( function() {

    try
    {
        //The problem: An exception is thrown due to the code below. The exception is:
        //ReferenceError: require is not defined 
        var A_Module = require('file1.js');
        var fooValue = A_Module().foo();
    }

    catch(err)
    {
        alert(err);
    }

});

file1 has a function I am trying to export while file2 tries to consume file1's exported function. The problem I have is that file2 throws this exception:

ReferenceError: require is not defined

Does anyone know how to fix this (note, it works fine when they are in Lib-folder, but I need them in the Data-Folder)?

Was it helpful?

Solution

@Phil: you cannot share code between the data folder (can interact with content) and the lib folder ( can interact with Mozilla apis directly) for security reasons. If you need to communicate between the two, you need to use asynchronous message passing. For more info on how all of this works, see the docs: https://addons.mozilla.org/en-US/developers/docs/sdk/1.4/dev-guide/addon-development/web-content.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top