Undefined variable causes huge verbose output from `esm.js` - javascript

I'm not sure why, but since upgrading to Node v16 from Node v14, I get this error only when I run node like node -r esm and there is a ReferenceError like:
ReferenceError: myVar is not defined
It causes a massive, 5000 line output of the esm.js module. How can I get rid of this?
const __global__ = this;(function (require, module, __shared__) { var __shared__;const e=module,t={Array:global.Array,Buffer:global.Buffer,Error:g
lobal.Error,EvalError:global.EvalError,Function:global.Function,JSON:global.JSON,Object:global.Object,Promise:global.Promise,RangeError:global.Ran
geError,ReferenceError:global.ReferenceError,Reflect:global.Reflect,SyntaxError:global.SyntaxError,TypeError:global.TypeError,URIError:global.URIE
rror,eval:global.eval},r=global.console;module.exports=(function(e){var t={};function r(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,export
s:{}};return e[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.d=function(e,t,r){Reflect.defineProperty(e,t,{configurable:!0,enumerable
:!0,get:r})},r.n=function(e){return e.a=e,function(){return e}},r(r.s=2)})([(function(e,t){var r;t=e.exports=$,"object"==typeof process&&process,r
=function(){},t.SEMVER_SPEC_VERSION="2.0.0";var i=256,n=Number.MAX_SAFE_INTEGER||9007199254740991,s=t.re=[],a=t.src=[],o=0,u=o++;a[u]="0|[1-9]\\d*
";var l=o++;a[l]="[0-9]+";var c=o++;a[c]="\\d*[a-zA-Z-][a-zA-Z0-9-]*";var p=o++;a[p]="("+a[u]+")\\.("+a[u]+")\\.("+a[u]+")";var h=o++;a[h]="("+a[l
]+")\\.("+a[l]+")\\.("+a[l]+")";var f=o++;a[f]="(?:"+a[u]+"|"+a[c]+")";var d=o++;a[d]="(?:"+a[l]+"|"+a[c]+")";var m=o++;a[m]="(?:-("+a[f]+"(?:\\."
+a[f]+")*))";var v=o++;a[v]="(?:-?("+a[d]+"(?:\\."+a[d]+")*))";var g=o++;a[g]="[0-9A-Za-z-]+";var y=o++;a[y]="(?:\\+("+a[g]+"(?:\\."+a[g]+")*))";v
ar x=o++,b="v?"+a[p]+a[m]+"?"+a[y]+"?";a[x]="^"+b+"$";var w="[v=\\s]*"+a[h]+a[v]+"?"+a[y]+"?",E=o++;a[E]="^"+w+"$";var S=o++;a[S]="((?:<|>)?=?)";v
ar R=o++;a[R]=a[l]+"|x|X|\\*";var P=o++;a[P]=a[u]+"|x|X|\\*";var _=o++;a[_]="[v=\\s]*("+a[P]+")(?:\\.("+a[P]+")(?:\\.("+a[P]+")(?:"+a[m]+")?"+a[y]
+"?)?)?";var k=o++;a[k]="[v=\\s]*("+a[R]+")(?:\\.("+a[R]+")(?:\\.("+a[R]+")(?:"+a[v]+")?"+a[y]+"?)?)?";var I=o++;a[I]="^"+a[S]+"\\s*"+a[_]+"$";var
A=o++;a[A]="^"+a[S]+"\\s*"+a[k]+"$";var N=o++;a[N]="(?:^|[^\\d])(\\d{1,16})(?:\\.(\\d{1,16}))?(?:\\.(\\d{1,16}))?(?:$|[^\\d])";var C=o++;a[C]="(?
:~>?)";var O=o++;a[O]="(\\s*)"+a[C]+"\\s+",s[O]=RegExp(a[O],"g");var T=o++;a[T]="^"+a[C]+a[_]+"$";var M=o++;a[M]="^"+a[C]+a[k]+"$";var L=o++;a[L]=
"(?:\\^)";var D=o++;a[D]="(\\s*)"+a[L]+"\\s+",s[D]=RegExp(a[D],"g");var F=o++;a[F]="^"+a[L]+a[_]+"$";var j=o++;a[j]="^"+a[L]+a[k]+"$";var V=o++;a[
V]="^"+a[S]+"\\s*("+w+")$|^$";var G=o++;a[G]="^"+a[S]+"\\s*("+b+")$|^$";var B=o++;a[B]="(\\s*)"+a[S]+"\\s*("+w+"|"+a[_]+")",s[B]=RegExp(a[B],"g");
v..........
How can I stop node from printing this to the console?

Try resetting your computer. It works for me.

Related

AppJS --harmony issue?

I'm using msvc and have nodejs tools setup in it. Fairly new to node.js but all the other npm packages i've simply installed via command line or through nodejs tools and they have worked. AppJS however gives me the error when I call require('appjs').
throw new Error('AppJS requires Node is run with the --harmony command
line)
Anyone know how to fix this? I get this error even when calling my script from command line doing
node --harmony app.js
Actual code
var serialPortLib = require("serialport");
var appjs = require('appjs');
var serialPort = new serialPortLib.SerialPort("COM13",{
baudrate : 250000,
parser : serialPortLib.parsers.readline('\n')
});
serialPort.on('open', function () { console.log('open'); serialPort.write("Sup!\n");});
serialPort.on('data',function(data){ console.log(data);})

node.js: suppress require()'s echoing of parse errors to stderr

node.js 10.26 will rightfully throw an error when you try to require a file that is not valid javascript (or JSON).
My problem is that it also outputs to stderr:
borken.js - know to be broken javascript file
,,>Z>badfile!=-csa&asd;'asdl ds]=}{ADS}DAS:LMFSV'
test.js
try {
var borken = require('./borken');
} catch (e) {} finally {
console.log('finally!');
}
Expected
$ node test.js
finally!
Actual
$ node test.js
/path/to/borken.js:1
(function (exports, require, module, __filename, __dirname) { asd;'asdl
^^^^^
finally!
The first three lines are output to stderr (running as node test.js 2> /dev/null suppresses them).
Is there any way to get rid of them?
What I've done so far:
I debugged while following the source and narrowed down the culprit to:
lib/module.js:439
var compiledWrapper = runInThisContext(wrapper, filename, true);
runInThisContext is defined in lib/vm.js, which unfortunately is a C++ wrapper, so I couldn't really follow what is going on through there.
I guess I'm looking for a magic "don't spam stderr" flag or any knowledge of this being fixed in any latest versions.
Apparently this has been fixed in the dev branch (0.11.x) but not in the latest stable (0.10.29)
Github issue: Syntax errors are printed to stderr, even when wrapped with try/catch #6920

Errors local collection: coffeescript vs javascript

In my project i'm using coffeescript.
But today, something I can not understand....
In /client/helpers/errors.coffee I write:
Errors = new Meteor.Collection(null)
and nothing works! In Chrome console:
Exception from Deps recompute: ReferenceError: Errors is not defined
But when I remove /client/helpers/errors.coffee and add /client/helpers/errors.js with
Errors = new Meteor.Collection(null);
everything works! How is this possible?
$ mrt list --using
...
coffeescript
What am I doing wrong?
$ meteor --version
Release 0.7.0.1
Use #Errors = new Meteor.Collection(null) instead

Uncaught exception with qunit and jquery

I'm facing an issue while trying to get javascript unit tests to work at the command line using qunit.
Here's some sample code to reproduce the error:
file util.js:
function abc() {
return 'abc';
}
if (typeof module !== 'undefined' && module.exports) {
module.exports = {
abc: abc
};
}
file util-tests.js
var qunit = require("qunit");
test("Test abc function", function () {
equal(util.abc(), 'abc');
});
With these files, I can run tests using the following command (gives a table-like output in the shell with the test results):
qunit -c util:util.js -t util-tests.js
Now it breaks if I add the following to util.js
$(document).ready(function () {
/* some code here */
});
Here's the error output:
qunit -c util:util.js -t util-tests.js
Testing /home/mfrere/jstst/util.js ... [Error: Uncaught exception in child process.]
same problem with:
var a = $;
or:
var a = document;
So this makes me think that I need to import jQuery somehow, so I thought about adding jquery.js as a dependency to the command, like this:
qunit -c util:util.js -t util-tests.js -d jquery.js
The above command gives me the same 'Uncaught exception' error, even if util.js doesn't contain any reference to '$'.
I'll probably need to do something else to get qunit to recognize 'document' as well, but I don't know what or how.
Now here's my question: what should I do to get this to work? It is important to keep in mind I want to test my files at the command line, not in a browser.
Just in case I did something wrong in the setup process, this is how I installed node/qunit (under ubuntu):
git clone git://github.com/creationix/nvm.git ~/.nvm
in .bashrc, I added the following line:
source ~/.nvm/nvm.sh
picked a specific version of node
nvm install v0.9.2
nvm alias default 0.9
and installed qunit
npm install -g qunit
finally I had to add this in .bashrc as well:
export NODE_PATH=~/.nvm/v0.9.2/lib/node_modules
You haven't imported jQuery:
$ = require('jquery'),
jQuery = require('jquery');
If you're using browserify, change that to 'jquery-browserify'.

Syntax check for JavaScript using command

Are there equivalent to perl -c syntax check for JavaScript from command? Given that I have NodeJS installed?
JSLint is not considered as it is not a real parser. I think YUI compressor is possible but I don't want to install Java on production machines, so I am checking if Node.JS already provided this syntax check mechanism.
If you want to perform a syntax check like that way we do in perl ( another scripting language) you can simply use node -c <js file-name>
e.g. a JS file as test.js has:
let x = 30
if ( x == 30 ) {
console.log("hello");
else {
console.log( "world");
}
now type in node -c test.js
it will show you
test.js:5
else {
^^^^
SyntaxError: Unexpected token else
at startup (bootstrap_node.js:144:11)
at bootstrap_node.js:509:3
Now after fixing the syntax issue as
let x = 30
if ( x == 30 ) {
console.log("hello");
} else {
console.log( "world");
}
check syntax - node -c test.js will show no syntax error!!
Note - we can even use it to check syntax for all files in a dir. - node -c *.js
Try uglify. You can install it via npm.
Edit: The package name has changed. It is uglify-js.
nodejs --help
explains the -p switch: it evaluates the supplied code and prints the results. So using nodejs -p < /path/to/file.js would be a disastrous way to check the validity of node.js code on your server. One possible solution is the one indicated in this SO thread. The one thing not so good about it - the syntax error messages it reports are not terribly helpful. For instance, it tell you something is wrong but without telling you where it is wrong.

Categories