If you write script like this in head tag, its not loaded synchronously in browser. main.js took long time to load as compare to app.js in browser. Hence you getting this error. Try to load app.js via main.js file
Your have to use shim : {} to define dependencies in requireJS config file.
main.js
require.config({
paths: {
'angular': '../lib/angular/angular',
'angular-route': '../lib/angular-route/angular-route',
'domReady': '../lib/requirejs-domready/domReady'
},
/**
* for libs that either do not support AMD out of the box, or
* require some fine tuning to dependency mgt'
*/
shim: {
'angular': {
exports: 'angular'
},
'angular-route': {
deps: ['angular']
}
},
deps: [
// kick start application... see bootstrap.js
'./bootstrap'
]
});
In main.js you have to bootstrap your angular App and then have to call app.js from bootstrap.js
bootstrap.js
define([
'require',
'angular',
'app',
'routes'
], function (require, ng) {
'use strict';
/*
* place operations that need to initialize prior to app start here
* using the `run` function on the top-level module
*/
require(['domReady!'], function (document) {
ng.bootstrap(document, ['app']);
});
});
here in bootstrap file your app.js is called so always you app.js is called after main.js
For more information about angular with requireJS please refer startersquad example.
Read this documentation for more information.
data-main="scripts/app"andapp.jsshould be written as a require.js module.