ReferenceError: require is not defined

2,799 views
Skip to first unread message

Erik Vold

unread,
Jan 4, 2011, 11:46:13 PM1/4/11
to mozilla-la...@googlegroups.com
I got a "ReferenceError: require is not defined" error when trying to require a module from within a context menu's contentScript. The jetpack module is one that I made awhile ago which simply exports the methods provided by Components.utils.import("resource://gre/modules/Microformats.js");. This jsm module exports a method called get(), which requires a DOM element as an argument. So I can't use the module from within main.js afacit, and since I can't use require() within the contentScript of a context menu either.. it seems like I can't use this module.

or is there something that I've missed? can I use handles here?

Friedrich Haussmann

unread,
Apr 23, 2011, 11:40:40 AM4/23/11
to mozilla-la...@googlegroups.com
I am trying to use
require("something_inside_lib_dir")
inside a
contentScriptFile: self.data.url("file_inside_data_dir")
but I am running into the same error

ReferenceError: require is not defined

The system is running addon-sdk-1.0b4 and Firefox 4.

Since I am quite new to javascript development maybe I should use a different design principle, but searching in this mailinglist and in the jetpack documentation did not help. I would welcome any assistance.

Cheers,
Friedrich

Hernan Rodriguez Colmeiro

unread,
Apr 23, 2011, 5:49:48 PM4/23/11
to mozilla-la...@googlegroups.com

Some extra code to know what's the context of the require call would
help. Having the full source of the file where you're having the
problem would greatly help.

Hernán

KWierso

unread,
Apr 23, 2011, 6:12:22 PM4/23/11
to mozilla-labs-jetpack
IIRC, you can't require modules from within the contentscript file.
Best you can do is loading it in the addon's context and then use
message passing to/from the content script to get things done.

On Apr 23, 10:40 am, Friedrich Haussmann <friedr...@haussmann.tel>
wrote:

Sean McArthur

unread,
Apr 24, 2011, 1:44:56 AM4/24/11
to mozilla-la...@googlegroups.com
Correct. In the content script files, its just like normal DOM-y JavaScript.  require is mechanism used in many newer JavaScript environments, like Node, and Jetpack, but it's not a standard, and so not in browsers to use with HTML.

KWierso

unread,
Apr 24, 2011, 12:49:55 PM4/24/11
to mozilla-labs-jetpack
Now, page-mod's constructor CAN take an array of URLs for the
contentScriptFile attribute. So you can load more than one file into
your page-mod's context.

Werdon Morris

unread,
Apr 25, 2011, 5:21:38 PM4/25/11
to mozilla-la...@googlegroups.com
So, then just delete the comment, and issue, and it will no longer be a problem.

> --
> You received this message because you are subscribed to the Google Groups
> "mozilla-labs-jetpack" group.
> To post to this group, send email to mozilla-la...@googlegroups.com.
> To unsubscribe from this group, send email to
> mozilla-labs-jet...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mozilla-labs-jetpack?hl=en.
>
>


--
Werdon W. Morris III, AKA. Butch

Reply all
Reply to author
Forward
0 new messages