I have the following in my main.js file:
/*--- Require.js: the main module loader ---*/
require.config({
baseUrl: '/javascripts/libs/home/',
waitSeconds: 0,
paths : {
jquery : '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min',
jqueryui : '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min',
underscore : '/javascripts/libs/vendor/underscore/underscore-min',
backbone : 'vendor/backbone/backbone.min',
marionette : 'vendor/backbone.marionette/backbone.marionette.min',
tpl : 'vendor/require/tpl',
moment : 'vendor/moment/moment',
datetimepicker : 'vendor/datetimepicker/jquery.datetimepicker.min',
tipso : 'vendor/tipso/tipso.min'
},
shim : {
underscore: {
exports: '_'
},
backbone: {
deps : ['jquery', 'underscore'],
exports : 'Backbone'
},
marionette: {
deps : ['jquery', 'underscore', 'backbone'],
exports : 'Marionette'
},
datetimepicker: {
deps : ['jquery', 'jqueryui'],
exports : 'Datetimepicker'
},
tipso: {
deps : ['jquery'],
exports : 'Tipso'
}
},
config: {
moment: {
noGlobal: false
}
}
});
//--- Define Google maps to make it globally accessible throughout the application ---//
define('gmaps', ['require_async!https://maps.googleapis.com/maps/api/js?v=3&libraries=geometry,places&key=AIzaSyDRKg-SNBODA1mKMCRrfMrls48x7owr9w8&sensor=true"'],
function(){
// return the gmaps namespace for brevity
return window.google.maps;
});
// --- Initialize the application ---//
require(["zwoop"], function(Zwoop){
Zwoop.start();
});
When trying to optimize the file with r.js, I get the following error:
Error: Tried loading "zwoop" at /javascripts/libs/home/zwoop.js then tried node's require("zwoop") and it failed with error: Error: Cannot find module 'zwoop' at /usr/lib/node_modules/requirejs/bin/r.js:2562:27 at Object.context.execCb (/usr/lib/node_modules/requirejs/bin/r.js:1921:33) at Object.Module.check (/usr/lib/node_modules/requirejs/bin/r.js:1125:51) at Object.Module.enable (/usr/lib/node_modules/requirejs/bin/r.js:1412:22) at Object.Module.init (/usr/lib/node_modules/requirejs/bin/r.js:1033:26) at callGetModule (/usr/lib/node_modules/requirejs/bin/r.js:1439:63) at Object.context.completeLoad (/usr/lib/node_modules/requirejs/bin/r.js:1815:21) at Function.req.load (/usr/lib/node_modules/requirejs/bin/r.js:2575:17) at Object.context.load (/usr/lib/node_modules/requirejs/bin/r.js:1910:21) at Object.Module.load (/usr/lib/node_modules/requirejs/bin/r.js:1079:29)
"Zwoop" is just a require module that loads my app. It runs correctly without the optimisation and the path is clearly correct.
Any idea what my cause this error?
If you don't define the path of a dependency into the
pathsconfig it will look for the dependency into thebaseUrldirectory. So either there's noswoop.jsfile into yourbaseUrldirectory either it's not defined as a proper module :define([...], function(...){ ... })