Re: [jetpack] Nested requires not working with sdk 1.9+

24 views
Skip to first unread message

Erik Vold

unread,
Nov 24, 2012, 4:43:13 PM11/24/12
to mozilla-la...@googlegroups.com
Are these files in the lib directory for your add-on? or just in the root?

Erik

On Fri, Nov 16, 2012 at 10:53 AM, Tony <tonyp...@gmail.com> wrote:
I have a questions about importing via require.

With sdk version 1.8, the following worked:

main.js
folder
   someFunctionality.js
   moreFunctionality.js
   utils.js

****
In main.js:

var foo = require("./folder/someFunctionality");
foo.bar(); // etc.
****
In someFunctionality.js:

var utils = require("./utils"); // TypeError: require is not a function
var moreFunctionality = require("./moreFunctionality");
utils.foo(); // etc
moreFunctionality.bar(); //etc

In moreFunctionality.js:

var utils = require("./utils"); // After flattening out directory structure: TypeError: require is not a function
utils.foo(); // etc

****
When I tried to upgrade to 1.9 (and 10 and 11), I got an error in someFunctionality.js that "require" is not a function.

TypeError: require is not a function

I played around a bit, and by flattening out the directory structure, "require" was defined in "someFunctionality", but it was not defined in "moreFunctionality".  

Obviously I don't have a good understand of how require is supposed to work.  Also I didn't see anything in the 1.9 release notes or the docs that explained what I was doing wrong before such that this stopped working.

Any help would be appreciated

--
You received this message because you are subscribed to the Google Groups "mozilla-labs-jetpack" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mozilla-labs-jetpack/-/X5dHkQIIBf0J.
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.

Friedrich Haussmann

unread,
Nov 24, 2012, 4:46:27 PM11/24/12
to mozilla-la...@googlegroups.com
Dear Tony

I am no jetpack developer, though I wrote an addon using the jetpack sdk.I just upgraded to 1.11 to check if it had any problems with require but it did run just fine.

You could try to work through the documentation at https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/guides/commonjs.html .

Some things I would check:
* are the files below the lib/ directory and not the data/ directory
* is there accidentally some "delete require" operation

If this did not help you, try to rebuild the minimal example in the aforementioned documentation. Then post your files in a zip if you still have problems.

Yours faithfully,
Friedrich Haussmann

Irakli Gozalishvili

unread,
Nov 30, 2012, 5:44:38 PM11/30/12
to mozilla-la...@googlegroups.com, Tony
In a future please provide example in add-on builder or somewhere else so it's clear what's wrong with a code.


Regards
--
Irakli Gozalishvili
Web: http://www.jeditoolkit.com/

--
You received this message because you are subscribed to the Google Groups "mozilla-labs-jetpack" group.
Reply all
Reply to author
Forward
0 new messages