I create a project with :
mvn archetype:generate -DarchetypeGroupId=com.github.searls -DarchetypeArtifactId=jasmine-archetype -DarchetypeVersion=1.3.1.5 -DgroupId=com.acme -DartifactId=my-jasmine-project -Dversion=0.0.1-SNAPSHOT
First I test with mvn jasmine:test the test are run normally.
note : I use maven 3.2.1
In the "target" directory I add a folder "phantomjs-1.9.7-windows" where I put "phantomjs.exe"
I modifie my original pom.xml to add
...
<configuration>
<srcDirectoryName>${project.artifactId}/src/main/javascript</srcDirectoryName>
<webDriverClassName>org.openqa.selenium.phantomjs.PhantomJSDriver</webDriverClassName>
<webDriverCapabilities>
<capability>
<name>phantomjs.binary.path</name>
<value>${project.build.directory}/phantomjs-1.9.7-${os.phantomJS}/${run.phantomJS}</value>
</capability>
</webDriverCapabilities>
<preloadSources>
<source>${project.basedir}/src/main/javascript/libs/jquery-1.9.1.js</source>
<source>${project.basedir}/src/main/javascript/libs/angular.js</source>
<source>${project.basedir}/src/main/javascript/libs/angular-ui-router.js</source>
<source>${project.basedir}/src/main/javascript/libs/angular-resource.js</source>
</preloadSources>
</configuration>
...
I create a folder "libs" under "src/main/javascript" and I put in it :
- jquery-1.9.1.js
- angular.js
- angular-ui-router.js
- angular-resource.js
note : angular is in verion 1.2.23
After that I create an other folder "app" under "src/main/javascript" and I put in it : "app.module.js"
(function() {
'use strict';
angular.module('app', [
'app.Security.modules'
]);
})();
Under "src/main/javascript/app" I create a folder "security" and I put in it : "security.module.js"
(function() {
'use strict';
angular.module('app.Security.modules', []);
})();
and "cha_directive.js"
angular.module('app.Security.modules').directive('inputOld', InputAccessKeyManagement);
function InputAccessKeyManagement () {}
If I test with mvn jasmine:test I obtain an error :
[ERROR - 2015-02-26T08:12:49.751Z] Session [40eacc20-bd8f-11e4-a736-9934c466a5ff] - page.onError - stack:
(anonymous function) (http://localhost:51170/jasmine-project/src/main/javascript/libs/angular.js:1679)
ensure (http://localhost:51170/jasmine-project/src/main/javascript/libs/angular.js:1601)
module (http://localhost:51170/jasmine-project/src/main/javascript/libs/angular.js:1892)
(anonymous function) (http://localhost:51170/jasmine-project/src/main/javascript/app/security/cha_directive.js:1)
[WARNING] JavaScript Console Errors:
* Error: [$injector:nomod] Module 'app.Security.modules' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.2.23/$injector/nomod?p0=app.Security.modules
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.163s
[INFO] Finished at: Thu Feb 26 09:12:49 CET 2015
[INFO] Final Memory: 12M/210M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.searls:jasmine-maven-plugin:1.3.1.5:test (default-cli) on project jasmine-project: The jasmine-maven-plugin encountered an exception:
[ERROR] java.lang.RuntimeException: java.lang.RuntimeException: There were javascript console errors.
[ERROR] at com.github.searls.jasmine.runner.SpecRunnerExecutor.execute(SpecRunnerExecutor.java:46)
[ERROR] at com.github.searls.jasmine.mojo.TestMojo.executeSpecs(TestMojo.java:86)
If I just rename "cha_directive.js" in "toto_directive.js" (with the same source code) and I run mvn jasmine:test again the test are run normally.
If I use "cha_directive.js" name file and run mvn jasmine:bdd. After that I run the url http://localhost:8234 in FF the tests are run normally.
The only thing (if I edit the HTML code of "Jasmine Spec Runner" with fireBug) is that I can see this tag :
<head jmp_jserror="Error: [$injector:nomod] Module 'app.Security.modules' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. http://errors.angularjs.org/1.2.23/$injector/nomod?p0=app.Security.modules">
If I look in class SpecRunnerExecutor.java in "checkForConsoleErrors" there is a test :
WebElement head = driver.findElement(By.tagName("head"));
if (head != null) {
String jserrors = head.getAttribute("jmp_jserror");
if (StringUtils.isNotBlank(jserrors)) {
throw new RuntimeException("There were javascript console errors.");
}
}
note : other file name crash the tests : input_directive.js, accessKey_directive.js, ...
It is a problem of import script order.
I declare
(function() {
'use strict';
angular.module('app.Security.modules', []);
})();
in a file named "security.module.js"
and I try to use my declaration
angular.module('app.Security.modules')
.directive('inputOld', InputAccessKeyManagement);
function InputAccessKeyManagement () {}
in a file named "cha_directive.js"
If you don't specify a custom import script order the default one is alphabetical then "cha_directive.js" is before "security.module.js".
I solved the problem using a "customRunnerTemplate".
But maybe there was another way to do "prettier" ?
If anyone else comes across this, a good solution is to do something like this in your sourceInclude block:
<sourceInclude>
<include>**/*.module.js</include>
<include>**/*.controller.js</include>
<include>**/*.service.js</include>
...
Et cetera. Assuming you conform to having your modules defined in a file called something along the lines of 'example.module.js' the modules will be loaded first, then controller, et cetera
Related
I've been asked to do a project in Angular 1, and I've been having a nightmare of a time just trying to get the page to load the app code from bundle.js. I've currently got an error along the lines of
[$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:modulerr] Failed to instantiate module {"_invokeQueue":
[],"_configBlocks":[],"_runBlocks":[],"name":"approveComponent"} due to:
Error: [ng:areq] Argument 'module' is not a function, got Object
but the only approveComponent I've got is essentially a blank placeholder -
import angular from 'angular';
const approve = angular.module('approveComponent', []);
export default approve;
What can I do to get this actually running?
I'm using Webpack 4 to bundle everything. (NO errors from webpack.)
I have seen this error earlier.You need to pass module name not module in the dependency
ngModule = angular.module('webpack', [
require('./webpack/photocrop/client')//this is a object
])
You can simply require the file and just inject by name Like this
var firstModule = require('./webpack/myapp/client')
ngModule = angular.module('webpack', [
'firstModule'//this is should work
])
firstModule(ngModule)
SAMPLE GITHUB REPO
I'm Trying to run my app in production profile, i'm using jhipster-generator for spring-boot app and angular. The app only run the footer and the background but the rest of the aplication nope, The error
Uncaught Error: [$injector:modulerr] Failed to instantiate module myAppdue to:
Error: [$injector:nomod] Module 'myApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.5.8/$injector/nomod?p0=myApp
at http://localhost:8080/app/vendor-7004bf12ca.js:8:17716
at http://localhost:8080/app/vendor-7004bf12ca.js:8:27870
at n (http://localhost:8080/app/vendor-7004bf12ca.js:8:27343)
at http://localhost:8080/app/vendor-7004bf12ca.js:8:27655
at http://localhost:8080/app/vendor-7004bf12ca.js:9:4997
at r (http://localhost:8080/app/vendor-7004bf12ca.js:8:18164)
at f (http://localhost:8080/app/vendor-7004bf12ca.js:9:4845)
at rt (http://localhost:8080/app/vendor-7004bf12ca.js:9:6774)
at a (http://localhost:8080/app/vendor-7004bf12ca.js:8:25413)
at ie (http://localhost:8080/app/vendor-7004bf12ca.js:8:25723)
http://errors.angularjs.org/1.5.8/$injector/modulerr?p0=myApp&p1=Error%3A%20%5B%24injector%3Anomod%5D%20Module%20'myApp'%20is%20not%20available!%20You%20either%20misspelled%20the%20module%20name%20or%20forgot%20to%20load%20it.%20If%20registering%20a%20module%20ensure%20that%20you%20specify%20the%20dependencies%20as%20the%20second%20argument.%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.5.8%2F%24injector%2Fnomod%3Fp0%3DdigitalBlogApp%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A8%3A17716%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A8%3A27870%0A%20%20%20%20at%20n%20(http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A8%3A27343)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A8%3A27655%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A9%3A4997%0A%20%20%20%20at%20r%20(http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A8%3A18164)%0A%20%20%20%20at%20f%20(http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A9%3A4845)%0A%20%20%20%20at%20rt%20(http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A9%3A6774)%0A%20%20%20%20at%20a%20(http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A8%3A25413)%0A%20%20%20%20at%20ie%20(http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A8%3A25723)
at http://localhost:8080/app/vendor-7004bf12ca.js:8:17716
at http://localhost:8080/app/vendor-7004bf12ca.js:8:27870
at n (http://localhost:8080/app/vendor-7004bf12ca.js:8:27343)
at http://localhost:8080/app/vendor-7004bf12ca.js:8:27655
at http://localhost:8080/app/vendor-7004bf12ca.js:9:4997
at r (http://localhost:8080/app/vendor-7004bf12ca.js:8:18164)
at f (http://localhost:8080/app/vendor-7004bf12ca.js:9:4845)
at rt (http://localhost:8080/app/vendor-7004bf12ca.js:9:6774)
at a (http://localhost:8080/app/vendor-7004bf12ca.js:8:25413)
at ie (http://localhost:8080/app/vendor-7004bf12ca.js:8:25723)
http://errors.angularjs.org/1.5.8/$injector/modulerr?p0=myApp&p1=Error%3A%20%5B%24injector%3Anomod%5D%20Module%20'myApp'%20is%20not%20available!%20You%20either%20misspelled%20the%20module%20name%20or%20forgot%20to%20load%20it.%20If%20registering%20a%20module%20ensure%20that%20you%20specify%20the%20dependencies%20as%20the%20second%20argument.%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.5.8%2F%24injector%2Fnomod%3Fp0%3DdigitalBlogApp%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A8%3A17716%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A8%3A27870%0A%20%20%20%20at%20n%20(http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A8%3A27343)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A8%3A27655%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A9%3A4997%0A%20%20%20%20at%20r%20(http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A8%3A18164)%0A%20%20%20%20at%20f%20(http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A9%3A4845)%0A%20%20%20%20at%20rt%20(http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A9%3A6774)%0A%20%20%20%20at%20a%20(http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A8%3A25413)%0A%20%20%20%20at%20ie%20(http%3A%2F%2Flocalhost%3A8080%2Fapp%2Fvendor-7004bf12ca.js%3A8%3A25723)
at http://localhost:8080/app/vendor-7004bf12ca.js:8:17716
at http://localhost:8080/app/vendor-7004bf12ca.js:9:5273
at r (http://localhost:8080/app/vendor-7004bf12ca.js:8:18164)
at f (http://localhost:8080/app/vendor-7004bf12ca.js:9:4845)
at rt (http://localhost:8080/app/vendor-7004bf12ca.js:9:6774)
at a (http://localhost:8080/app/vendor-7004bf12ca.js:8:25413)
at ie (http://localhost:8080/app/vendor-7004bf12ca.js:8:25723)
at re (http://localhost:8080/app/vendor-7004bf12ca.js:8:24962)
at HTMLDocument.<anonymous> (http://localhost:8080/app/vendor-7004bf12ca.js:13:25627)
at p (http://localhost:8080/app/vendor-7004bf12ca.js:2:8692)
what can it be ?
It is probably due to something you changed in index.html because JHipster uses gulp to inject scripts and css into it when building for production. Compare your current version with the one you archived in git at project generation time.
I'm using yeoman generator for scaffolding angular web application with requirejs. Its working fine but when I tried to concat and minifying all the js file into a single file through grunt task runner its started giving me above mentioned error. I've researched online about the issue and common solution is I may be mis-spelled any service injecting in the module or service does not exists, I've cross checked again all the spelling, quotation marks etc everything seems fine but still I'm unable to resolve this issue.
Here is my app.js file where my main module with dependencies is listed.
return angular
.module('arteciateYeomanApp', [
'arteciateYeomanApp.controllers.MainCtrl',
'arteciateYeomanApp.controllers.AboutCtrl',
'arteciateYeomanApp.services.Xhr',
'arteciateYeomanApp.services.Common',
'arteciateYeomanApp.controllers.ArtworkCtrl',
'arteciateYeomanApp.controllers.AddAccountCtrl',
'arteciateYeomanApp.controllers.AddArtgroupCtrl',
'arteciateYeomanApp.controllers.AddArtistCtrl',
'arteciateYeomanApp.controllers.AddArtworkCtrl',
'arteciateYeomanApp.controllers.AddCampaignsCtrl',
'arteciateYeomanApp.controllers.AddGenreCtrl',
'arteciateYeomanApp.controllers.AddInstitutionCtrl',
'arteciateYeomanApp.controllers.AdminSignupCtrl',
'arteciateYeomanApp.controllers.ArtistInfoCtrl',
'arteciateYeomanApp.controllers.DirectUserSignupCtrl',
'arteciateYeomanApp.controllers.ErrorCtrl',
'arteciateYeomanApp.controllers.ForgotPasswordCtrl',
'arteciateYeomanApp.controllers.GroupBuyingCtrl',
'arteciateYeomanApp.controllers.LoginCtrl',
'arteciateYeomanApp.controllers.AdminLoginCtrl',
'arteciateYeomanApp.controllers.ResetPasswordCtrl',
'arteciateYeomanApp.controllers.SignupCtrl',
'arteciateYeomanApp.controllers.UnblockUserCtrl',
'arteciateYeomanApp.controllers.UpdatePasswordCtrl',
'arteciateYeomanApp.controllers.DashboardCtrl',
'ngRoute','ngResource']).config(.....);
here is grunt task which I'm running for minifying the js files.
registering task
grunt.registerTask('dev', ['requirejs' ]);
Here is task running script
requirejs : {
compile : {
options : {
baseUrl : "<%= yeoman.app %>/scripts",
mainConfigFile : "<%= yeoman.app %>/scripts/main.js",
name : "main",
out : "requireArterciate.js"
}
}
}
Please let me know if I'm doing something wrong here.
If you need to minify the angularjs code, then use the following standard format syntax to define the controller and to inject the dependencies. Refer Dependency Injection
angular.module('test').controller('testController', testController);
testController.$inject = ['$scope', '$rootScope'];
function testController($scope, $rootScope) {};
I'm testing an Angular app with Karma. I've got everything working, but it seems like I'm doing something wrong.
https://gist.github.com/guyjacks/7bca850844deb612e681
Karma will throw the following error if I comment out 'app/notes/notes.main.js' :
Uncaught Error: [$injector:nomod] Module 'notes.main' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.4.3/$injector/nomod?p0=notes.main
at /Users/guyjacks/projects/adr-demo/node_modules/angular/angular.js:1958
I don't want to have to manually list each application file to control the order in which each file loads. Am I don't something wrong or do I just have to list each file in the order I want?
---- Solution based on the accepted answer ----
My app is organized into modules as recommended by the Angular Style Guide: https://github.com/johnpapa/angular-styleguide.
'app/app.module.js',
'app/**/*.module.js',
'app/**/*.service.js',
'app/**/*.controller.js',
'app/**/*.directive.js',
'app/**/*.js'
I don't think the following lines are necessary above
'app/**/*.service.js',
'app/**/*.controller.js',
'app/**/*.directive.js'
when each module has an angular module declared in the *.module.js file like my app does.
That said, if you did need to explicitly load services before controllers & controllers before directives then this would be the way to do it.
Update : I could not see your karma file, now Gist link is fixed.
The point in notes[.]main.js is causing the problem,
So, 'app/**/*.js' is not matching notes.main.js.
Try now like this : app/**/*. *.js
=============================================================
Before update :
You have to load the modules that you app depends on, in karma config. file :
module.exports = function(config) {
config.set({
.......
// list of files / patterns to load in the browser
files: [
'./client/app/vendors/angular/angular.js',
// =====> load Your modules here ...
'./client/app/app.js',
'./client/app/controllers/*.js',
'./client/app/directives/*.js',
'./client/app/services/*.js',
'./test/client/unit/**/*.js'
],
.....
}) }
I have download the sample https://github.com/tastejs/todomvc/tree/master/examples/typescript-angular and I try to get it working under a VS2013 Web Application empty template.
I add all the file of the sample, I launch the website by IIS, it works fine.
But when I build the project (without modifying anything) the only lines that remain are :
/// <reference path='_all.ts' />
/**
* The main TodoMVC app module.
*
* #type {angular.Module}
*/
var todos;
(function (todos) {
'use strict';
var todomvc = angular.module('todomvc', []).controller('todoCtrl', todos.TodoCtrl).directive('todoBlur', todos.todoBlur).directive('todoFocus', todos.todoFocus).service('todoStorage', todos.TodoStorage);
})(todos || (todos = {}));
When I try to run the website I have the following error :
http://localhost/WebAppTodoMvc/bower_components/angular/angular.js
0x800a139e - Erreur d’exécution JavaScript: [$injector:modulerr] Failed to instantiate module todomvc due to
Error: [ng:areq] Argument 'directiveFactory' is required
That code is meant to work with the --out compiler flag and you should use _all.js generated from all.ts https://github.com/tastejs/todomvc/blob/master/examples/typescript-angular/js/_all.ts
You can specify this as the reference file from your project properties.