RequireJS Optimization Reference Error - javascript

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.

Related

gulp-angular-templatecache throwing error when piping angular templates

I'm having some difficulty with gulp-angular-templatecache. I have a gulpfile with a task:
gulp.task('templates', function() {
return gulp.src(paths.angularTemplates)
.pipe(templateCache())
/*.pipe(gulp.dest('javascript/angular'))*/;
});
I'm not sure why but the following error is thrown when piping to gulp-angular-templatecache and throws:
stream.js:74
throw er; // Unhandled stream error in pipe.
^
TypeError: Cannot read property 'toString' of null
at templateCacheFile (/home/vagrant/app/node_modules/gulp-angular-templatecache/index.js:89:40)
at wrappedMapper (/home/vagrant/app/node_modules/gulp-angular-templatecache/node_modules/event-stream/node_modules/map-stream/index.js:84:19)
at Stream.stream.write (/home/vagrant/app/node_modules/gulp-angular-templatecache/node_modules/event-stream/node_modules/map-stream/index.js:96:21)
at Stream.method [as write] (/home/vagrant/app/node_modules/gulp-angular-templatecache/node_modules/event-stream/node_modules/duplexer/index.js:47:39)
at write (/home/vagrant/app/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24)
at flow (/home/vagrant/app/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7)
at DestroyableTransform.pipeOnReadable (/home/vagrant/app/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:664:5)
at emitNone (events.js:67:13)
at DestroyableTransform.emit (events.js:166:7)
at emitReadable_ (/home/vagrant/app/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:448:10)
I'm not sure what problem this error is related to. Any help would be greatly appreciated.
Many thanks.
there was a newer gulp-angular-templatecache version which broke the it. Ended up specifying a specific version in the gulpfile
In my project this was caused by a folder name with a dot inside.
So, I had a folder called folder_name.html and had to rename it to folder_name.
(Using gulp-angular-templatecache version 1.9.1)

Jade: ReferenceError: TokContext is not defined

I make my app.js simplest node server. To do that I installed next libs:
npm install node-jsx react express jade.
Now when I start it with node app.js it gets the next error:
c:\Programming\React_Examples\server rendering\node_modules\jade\node_modules\constantinople\node_modules\acorn\dist\acorn.js:2275
_classCallCheck(this, TokContext);
^
ReferenceError: TokContext is not defined
at new TokContext (c:\Programming\React_Examples\server rendering\node_modules\jade\node_modules\constantinople\node_modules\acorn\dist\acorn.js:2275:25)
at Object../state (c:\Programming\React_Examples\server rendering\node_modules\jade\node_modules\constantinople\node_modules\acorn\dist\acorn.js:2285:11)
at s (c:\Programming\React_Examples\server rendering\node_modules\jade\node_modules\constantinople\node_modules\acorn\dist\acorn.js:1:681)
at c:\Programming\React_Examples\server rendering\node_modules\jade\node_modules\constantinople\node_modules\acorn\dist\acorn.js:1:732
at Object../expression (c:\Programming\React_Examples\server rendering\node_modules\jade\node_modules\constantinople\node_modules\acorn\dist\acorn.js:907:21)
at s (c:\Programming\React_Examples\server rendering\node_modules\jade\node_modules\constantinople\node_modules\acorn\dist\acorn.js:1:681)
at e (c:\Programming\React_Examples\server rendering\node_modules\jade\node_modules\constantinople\node_modules\acorn\dist\acorn.js:1:852)
at c:\Programming\React_Examples\server rendering\node_modules\jade\node_modules\constantinople\node_modules\acorn\dist\acorn.js:1:870
at a (c:\Programming\React_Examples\server rendering\node_modules\jade\node_modules\constantinople\node_modules\acorn\dist\acorn.js:1:150)
at Object.<anonymous> (c:\Programming\React_Examples\server rendering\node_modules\jade\node_modules\constantinople\node_modules\acorn\dist\acorn.js:1:383)
The issue is a conflict between the node-jsx and acorn modules (the latter used by Jade).
If you can save all your JSX in files whose extension is something other than .js, say .jsx, you could replace your
require('node-jsx').install();
call with:
require('node-jsx').install({extension: '.jsx'});
Another alternative might be a different templating engine from Jade.
Or limiting your JSX includes to modules outside of your main one (not sure about this one, but worth trying if necessary).
See https://github.com/pugjs/jade/issues/1925

Error in minifed version of controller - angularjs?

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.

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

command line node.js; running script with modules

I'm doing some testing with node.js and several modules\libraries. For simplicity I'll focus on underscore.js.
When I run node.exe with the following source:
require("./underscore.js");
_.each({one : 1, two : 2, three : 3}, function(num, key){ console.log(num); });
I get:
C:\Dropbox\personal-work\foo\test code>node library-tests.js
node.js:208
throw e; // process.nextTick error, or 'error' event on first tick
^
ReferenceError: _ is not defined
at Object.<anonymous> (C:\Dropbox\personal-work\foo\test code\library-tests.js:2:1)
at Module._compile (module.js:425:26)
at Object..js (module.js:443:10)
at Module.load (module.js:344:31)
at Function._load (module.js:303:12)
at Array.<anonymous> (module.js:463:10)
at EventEmitter._tickCallback (node.js:200:26)
What is also strange is that when I run it like this:
node underscore.js library-tests.js
It doesn't seem to do anything at all...I've even added log statements, they don't seem to execute.
I've also tried pasting in the underscore.js source into the top of my source and I get the same error...
Does anyone know what I'm doing wrong here? Thanks.
try assigning it:
var _ = require('../underscore.js');
You can see here in the annotated source code that underscore will not add itself to the global namespace if it is running in a CommonJS implementation (of which, Node.JS is one).

Categories

Resources