Error in minifed version of controller - angularjs? - javascript

I am working on angularjs and node.js.
Problem:
I am getting following error in minified version of controller(Angular Controller js file). But it is working in the normal version.
Error:
Error: [$injector:unpr] http://errors.angularjs.org/1.2.25/$injector/unpr?p0=eProvider%20%3C-%20e
at Error (native)
at http://localhost:8080/assets/lib/js/angularjs/angular.min.js:6:450
at http://localhost:8080/assets/lib/js/angularjs/angular.min.js:36:202
at Object.c [as get] (http://localhost:8080/assets/lib/js/angularjs/angular.min.js:34:305)
at http://localhost:8080/assets/lib/js/angularjs/angular.min.js:36:270
at c (http://localhost:8080/assets/lib/js/angularjs/angular.min.js:34:305)
at d (http://localhost:8080/assets/lib/js/angularjs/angular.min.js:35:6)
at Object.instantiate (http://localhost:8080/assets/lib/js/angularjs/angular.min.js:35:165)
at http://localhost:8080/assets/lib/js/angularjs/angular.min.js:67:419
at link (http://localhost:8080/assets/lib/js/angularjs/angular-route.js:907:26) <div ng-view="" class="ng-scope">
I am using gulp-uglify to minify the controller
Code
gulp.task('buildControllerScript', function(){
return gulp.src(paths.controllers)
.pipe(concat('controllers.js'))
.pipe(gulp.dest('./public/dist/controllers/'))
.pipe(rename('controllers.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./public/dist/controllers/'));
});
Note:
Seems to be something wrong while uglify.
I cannot expose the controller code due to privacy rules
Any suggestion will be grateful.

Since Angular's dependency injection depends on the names of your function parameters, you either need to use dependency annotation or replace the uglify gulp plugin with gulp-ng-annotate.

Related

Webpack minimize option breaks application if set to true

I am experiencing an issue about webpack: if I set config.optimization.minimize: false, webpack produces not-minified bundle files (polyfills, vendor and app), then I run the server and all works fine. If I change the option to config.optimization.minimize: false I am getting following AngularJS (1.7.9) error:
jquery.min.js:2 Uncaught Error: [$injector:modulerr] Failed to instantiate module saServer2App due to:
Error: [$injector:modulerr] Failed to instantiate module saServer2App.account due to:
Error: [$injector:unpr] Unknown provider: e
https://errors.angularjs.org/1.7.9/$injector/modulerr?p0=saServer2App&p1=Error%3A%20%5B%24injector%3Amodulerr%5D%20Failed%20to%20instantiate%20module%20saServer2App.account%20due%20to%3A%0AError%3A%20%5B%24injector%3Aunpr%5D%20Unknown%20provider%3A%20e%0A%0Ahttps%3A%2F%2Ferrors.angularjs.org%2F1.7.9%2F%24injector%2Fmodulerr%3Fp0%3DsaServer2App.account%26p1%3DError%253A%2520%255B%2524injector%253Aunpr%255D%2520Unknown%2520provider%253A%2520e%250Ahttps%253A%252F%252Ferrors.angularjs.org%252F1.7.9%252F%2524injector%252Funpr%253Fp0%253De%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A9000%252Fvendor.bundle.js%253A7%253A837%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A9000%252Fvendor.bundle.js%253A7%253A23977%250A%2520%2520%2520%2520at%2520u%2520(http%253A%252F%252Flocalhost%253A9000%252Fvendor.bundle.js%253A7%253A25576)%250A%2520%2520%2520%2520at%2520s%2520(http%253A%252F%252Flocalhost%253A9000%252Fvendor.bundle.js%253A7%253A25881)%250A%2520%2520%2520%2520at%2520Object.invoke%2520(http%253A%252F%252Flocalhost%253A9000%252Fvendor.bundle.js%253A7%253A25969)%250A%2520%2520%2520%2520at%2520r%2520(http%253A%252F%252Flocalhost%253A9000%252Fvendor.bundle.js%253A7%253A25365)%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A9000%252Fvendor.bundle.js%253A7%253A25009%250A%2520%2520%2520%2520at%2520x%2520(http%253A%252F%252Flocalhost%253A9000%252Fvendor.bundle.js%253A7%253A1529)%250A%2520%2520%2520%2520at%2520g%2520(http%253A%252F%252Flocalhost%253A9000%252Fvendor.bundle.js%253A7%253A24869)%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%253A9000%252Fvendor.bundle.js%253A7%253A24955%250A%2520%2520%2520%2520at%2520x%2520(http%253A%252F%252Flocalhost%253A9000%252Fvendor.bundle.js%253A7%253A1529)%250A%2520%2520%2520%2520at%2520g%2520(http%253A%252F%252Flocalhost%253A9000%252Fvendor.bundle.js%253A7%253A24869)%250A%2520%2520%2520%2520at%2520We%2520(http%253A%252F%252Flocalhost%253A9000%252Fvendor.bundle.js%253A7%253A24189)%250A%2520%2520%2520%2520at%2520i%2520(http%253A%252F%252Flocalhost%253A9000%252Fvendor.bundle.js%253A7%253A10341)%250A%2520%2520%2520%2520at%2520Object.Et%2520%255Bas%2520bootstrap%255D%2520(http%253A%252F%252Flocalhost%253A9000%252Fvendor.bundle.js%253A7%253A10656)%250A%2520%2520%2520%2520at%2520HTMLDocument.%253Canonymous%253E%2520(http%253A%252F%252Flocalhost%253A9000%252Fapp.bundle.js%253A348%253A233259)%250A%2520%2520%2520%2520at%2520e%2520(http%253A%252F%252Flocalhost%253A9000%252Flibs%252Fjquery.min.js%253A2%253A30005)%250A%2520%2520%2520%2520at%2520t%2520(http%253A%252F%252Flocalhost%253A9000%252Flibs%252Fjquery.min.js%253A2%253A30307)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9000%2Fvendor.bundle.js%3A7%3A837%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9000%2Fvendor.bundle.js%3A7%3A25194%0A%20%20%20%20at%20x%20(http%3A%2F%2Flocalhost%3A9000%2Fvendor.bundle.js%3A7%3A1529)%0A%20%20%20%20at%20g%20(http%3A%2F%2Flocalhost%3A9000%2Fvendor.bundle.js%3A7%3A24869)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A9000%2Fvendor.bundle.js%3A7%3A24955%0A%20%20%20%20at%20x%20(http%3A%2F%2Flocalhost%3A9000%2Fvendor.bundle.js%3A7%3A1529)%0A%20%20%20%20at%20g%20(http%3A%2F%2Flocalhost%3A9000%2Fvendor.bundle.js%3A7%3A24869)%0A%20%20%20%20at%20We%20(http%3A%2F%2Flocalhost%3A9000%2Fvendor.bundle.js%3A7%3A24189)%0A%20%20%20%20at%20i%20(http%3A%2F%2Flocalhost%3A9000%2Fvendor.bundle.js%3A7%3A10341)%0A%20%20%20%20at%20Object.Et%20%5Bas%20bootstrap%5D%20(http%3A%2F%2Flocalhost%3A9000%2Fvendor.bundle.js%3A7%3A10656)%0A%20%20%20%20at%20HTMLDocument.%3Canonymous%3E%20(http%3A%2F%2Flocalhost%3A9000%2Fapp.bundle.js%3A348%3A233259)%0A%20%20%20%20at%20e%20(http%3A%2F%2Flocalhost%3A9000%2Flibs%2Fjquery.min.js%3A2%3A30005)%0A%20%20%20%20at%20t%20(http%3A%2F%2Flocalhost%3A9000%2Flibs%2Fjquery.min.js%3A2%3A30307)
at vendor.6729935a0c85787ce014.bundle.js:895
at vendor.6729935a0c85787ce014.bundle.js:5819
at x (vendor.6729935a0c85787ce014.bundle.js:1144)
at g (vendor.6729935a0c85787ce014.bundle.js:5779)
at We (vendor.6729935a0c85787ce014.bundle.js:5696)
at i (vendor.6729935a0c85787ce014.bundle.js:2719)
at Object.Et [as bootstrap] (vendor.6729935a0c85787ce014.bundle.js:2740)
at HTMLDocument.<anonymous> (app.js:74)
at e (jquery.min.js:2)
at t (jquery.min.js:2)
This is a bit strange, especially to me that I am new in AngularJS and Webpack. The only thing I change between the two scenarios is only the minimize flag. What could be wrong?
Feel free to ask some portions of my files/codes I needed.
AngularJs dependency injection is based on the function argument names.
For example:
class AuthService {
constructor(otherService) {
// ------------^ will inject otherService
}
}
angular.module('my-app', []).service('authService', AuthService);
The problem is that when you minify your code, the minifier will replace function arguments into something shorter (usually one char).
This is what happens in your case, this explains why the angular tries to inject e (Error: [$injector:unpr] Unknown provider: e).
In order to overcome this issue, angular supports array notation which defines the dependencies as a string.
// Given
const MyController = function (obfuscatedScope, obfuscatedRoute) {
// ...
};
// Define function dependencies
MyController['$inject'] = ['$scope', '$route'];
There is a webpack plugin which annotates automatically, ng-annotate-webpack-plugin.
It handles most of the cases, but sometime you need to help it by adding a special comment.
class AuthService {
/* #ngInject */
constructor(otherService) {
// ------------^ will inject otherService
}
}
angular.module('my-app', []).service('authService', AuthService);
If you are a babel user, check this babel plugin.

AdminCtrl is not using explicit annotation and cannot be invoked in strict? angular meteor

Error Snapshot Development when using ng-strict-di
I am developing project in meteor , If I don't use ng-strict-di in development it works fine but then in production(after making build ) I face following issue :
Error In Production Meteor
Development Error:
Error columnNumber: 12 fileName:
"localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6"
lineNumber: 895 message: "[$injector:strictdi] AdminCtrl is not using
explicit annotation and cannot be invoked in strict
mode\nerrors.angularjs.org/1.6.8/$injector/strictdi?p0=AdminCtrl"
stack:
"minErr/<#localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6:895:12\nannotate#localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6:5039:17\ninjectionArgs#localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6:5833:21\ninvoke#localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6:5868:18\n$controllerInit#localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6:11846:24\nnodeLinkFn#localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6:10709:35\ncompileTemplateUrl/<#localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6:11117:13\nprocessQueue#localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6:17939:37\nscheduleProcessQueue/<#localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6:17987:27\n$digest#localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6:19122:15\n$apply#localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6:19419:13\nbootstrapApply#localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6:2737:9\ninvoke#localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6:5876:16\ndoBootstrap#localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6:2735:5\nbootstrap#localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6:2755:12\nangularInit#localhost:3007/packages/modules.js?hash=f352b06ef868d8ef612a0e02d3fc1da778e4f6d6:2640:5\nangular.js/proto: Object { … }
Production(Build )
Error: [$injector:unpr] Unknown provider: tProvider <- t
errors.angularjs.org/1.6.8/$injector/unpr?p0=tProvider%20%3C-%20t
Stack trace:
r/<#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:11:7828
he/b.$injector<#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:11:30527
r#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:11:29436
he/E<#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:11:30610
r#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:11:29436
i#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:11:29741
a#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:11:29962
t#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:12:25404
p#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:12:11871
ht/<#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:12:17718
u#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:13:15438
l/<#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:13:15884
$digest#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:13:21599
$apply#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:13:23411
t#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:11:16603
a#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:11:30066
a#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:11:16522
lt#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:11:16810
ct#localhost:3008/7084ab3720bb9d2b53502cd2b81dce478c095b4c.js?meteor_js_resource=true:11:16046
angular.js/
You're bootstrapping Angular in strict dependency injection mode. This causes angular to throw exceptions when it encounters a dependency that isn't explicitly annotated. This is a way to enforce developers to guard against names of dependencies getting minified.
From the documentation:
If this attribute is present on the app element, the injector will be
created in "strict-di" mode. This means that the application will fail
to invoke functions which do not use explicit function annotation (and
are thus unsuitable for minification), as described in the Dependency
Injection guide, and useful debugging info will assist in tracking
down the root of these bugs.
The error tells you that you havn't explicitly annotated your AdminCtrl-controller. To fix this, your code should look similar to this:
angular.module('app').controller('AdminCtrl', ['firstDependency', 'secondDependency',
function(firstDependency, secondDependency){
// Controller body
}]);
or using $inject:
angular.module('app').controller('AdminCtrl', AdminCtrl);
AdminCtrl.$inject = ['firstDependency', 'secondDependency'];
function AdminCtrl(firstDependency, secondDependency){
// Controller body
}
The second method can be done for you automatically if you use build tools such as grunt, gulp or webpack, along with the ngAnnotate package.

Including Angular-UI-Validate in my project

The project uses Angular 1.3 (from a CDN, links removed below) and I'm trying to install Angular-UI-Validate. I have included both in script tags, and in the inspector, I can see that they're both getting retrieved correctly. Still, it seems as if I'm missing something:
Error: [$injector:unpr] http://errors.angularjs.org/1.3.10/$injector/unpr?p0=ui.validateProvider%20%3C-%20ui.validate%20%3C-%20app.runtimeStackAdminController
at Error (native)
at https://***.cdn.net/1.5/libs/angular.js/1.3.10/angular.min.js:6:417
at https://***.cdn.net/1.5/libs/angular.js/1.3.10/angular.min.js:38:307
at Object.d [as get] (https://***.cdn.net/1.5/libs/angular.js/1.3.10/angular.min.js:36:308)
at https://***.cdn.net/1.5/libs/angular.js/1.3.10/angular.min.js:38:381
at d (https://***.cdn.net/1.5/libs/angular.js/1.3.10/angular.min.js:36:308)
at e (https://***.cdn.net/1.5/libs/angular.js/1.3.10/angular.min.js:37:64)
at Object.g.instantiate (https://l***.cdn.net/1.5/libs/angular.js/1.3.10/angular.min.js:37:213)
at b.$get (https://***.cdn.net/1.5/libs/angular.js/1.3.10/angular.min.js:76:318)
at $route.link (https://***.cdn.net/1.5/libs/angular.js/1.3.10/angular-route.js:981:26) <div id="ng-view-wrapper" class="container-fluid ng-scope" ng-view="" autoscroll="true">
Am I missing a library that I have to include? Thanks in advance!
You need to load the ui.validate module.
See https://github.com/angular-ui/ui-validate#usage for all instructions.

JCIFS Package Reference Error in Javascript

I am trying to use JCIFS to access file in a shared folder and it works perfectly fine using a java program. But when I try to use this code in a javascript which is embedded in a ant script file I get the below error. I do see the jcifs-1.3.17.jar in the classpath of ANT but still it is complaining of reference error (ReferenceError: "jcifs" is not defined.).
Appreciate your inputs/thoughts on this. Thanks in Advance!!!
2014-07-17 11:41:32,739 ERROR org.apache.bsf.BSFManager - Exception :
java.security.PrivilegedActionException: org.apache.bsf.BSFException: JavaScript Error: Internal Error: org.mozilla.javascript.EcmaError: **ReferenceError: "jcifs" is not defined.**
at java.security.AccessController.doPrivileged(AccessController.java:255)
at org.apache.bsf.BSFManager.exec(BSFManager.java:491)
at org.apache.tools.ant.util.optional.ScriptRunner.executeScript(ScriptRunner.java:100)
at org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:52)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:600)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: org.apache.bsf.BSFException: JavaScript Error: Internal Error: org.mozilla.javascript.EcmaError: ReferenceError: "jcifs" is not defined.
at org.apache.bsf.engines.javascript.JavaScriptEngine.handleError(JavaScriptEngine.java:195)
at org.apache.bsf.engines.javascript.JavaScriptEngine.eval(JavaScriptEngine.java:147)
at org.apache.bsf.util.BSFEngineImpl.exec(BSFEngineImpl.java:141)
at org.apache.bsf.BSFManager$6.run(BSFManager.java:493)
at java.security.AccessController.doPrivileged(AccessController.java:251)
... 19 more
Need to preface the package name with Packages.
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scripting_Java#External_Packages_and_Classes

RequireJS Optimization Reference Error

I am using RequireJS to organise my JS files. I am attempting optimize my files into one main JS file.
I am using the following command to do this:
/home/plugins/requireJS/build/build.sh name=main out=mesh-built.js baseUrl=/home/public_html/js/ includeRequire=true
The command produces the following error:
Tracing dependencies for: main
node.js:116
throw e; // process.nextTick error, or 'error' event on first tick
^
ReferenceError: $ is not defined
at eval at <anonymous> (/home/plugins/requireJS/bin/../build/jslib/requirePatch.js:147:21)
at Function.<anonymous> (eval at <anonymous> (/home/plugins/requireJS/bin/../build/jslib/requirePatch.js:147:21))
at Function.load (/home/plugins/requireJS/bin/../build/jslib/requirePatch.js:147:21)
at loadPaused (require.js:916:21)
at require.js:958:21
at Object.completeLoad (require.js:1207:17)
at Function.load (/home/plugins/requireJS/bin/../build/jslib/requirePatch.js:150:29)
at loadPaused (require.js:916:21)
at require.js:958:21
at Object.completeLoad (require.js:1207:17)
Does anyone know why it would be producing this error?
Many thanks.
I think its a problem with the order of the files to include. Make sure the JS file which defines the $() is included first.

Categories

Resources