Joined August 2013
·

Serkan Sipahi

Germany / Hamburg
·
·

This errors occur if i use requirejs in chrome-extension. Without chrome-extension, also call over script-tag( <script data-main="js/main" src="js/lib/requirejs/require.js"></script> ) everything works well.

If i require('backbone') in test.js( see below ) i get an error --> Uncaught TypeError: Cannot call method 'each' of undefined ! i believe backbone cant call "each" method because underscore is not loaded completely ( see http://tinypic.com/view.php?pic=6j3a08&s=5 )

What am I doing wrong?

manifest.json file

{
"manifestversion": 2,

.....
.....
....
"content
scripts": [
{
"matches": ["<all_urls>"],
"js": [
"js/lib/requirejs/require.js",
"js/lib/requirejs/require-cs.js",
"js/main.js"
]
}
],
.....
.....
.....
}

main.js

requirejs.config({
baseUrl: chrome.extension.getURL("/"),
urlArgs: "v=" + (new Date()).getTime(),
paths: {
app : 'js/app',
jquery: 'js/lib/jquery/jquery',
backbone : 'js/lib/backbone/backbone',
underscore : 'js/lib/underscore/underscore'
},
shim : {
jquery : {
exports : '$'
},
backbone: {
deps: ['jquery', 'underscore'],
exports: 'Backbone'
},
underscore : {
exports : '_'
}
}

});
require(['app/test'], function (test) {
console.log(test);
});

define() file test.js

define(function(require){

var $ = require('jquery');

$('body').append('<div id="foo">im appended over requirejs</div>');
$('body').on({
        click : function(){
              var Backbone = require('backbone');
              console.log(Backbone);
        }
}, '#foo');

return {
    foo : 'foo',
    hoo : 'huu'
};

});

Achievements
29 Karma
0 Total ProTip Views
Interests & Skills