Problematic load of google libphonenumber - javascript

I can't load the libphonenumber. I get this stack trace that I can't figure out.
The error occurs at the require line:
var gp = require('google-libphonenumber').PhoneNumberUtil.getInstance();
number.js:1058
throw a;
^
AssertionError: Assertion failed
at new goog.asserts.AssertionError (...../node_modules/google-libphonenumber/dist/libphonenumber.js:1051:20)
at Object.goog.asserts.doAssertFailure_ (..../node_modules/google-libphonenumber/dist/libphonenumber.js:1068:7)
at Object.goog.asserts.assert [as assert] (..../node_modules/google-libphonenumber/dist/libphonenumber.js:1075:53)
at new goog.proto2.FieldDescriptor (..../node_modules/google-libphonenumber/dist/libphonenumber.js:1553:16)
at Function.goog.proto2.Message.createDescriptor (..../node_modules/google-libphonenumber/dist/libphonenumber.js:2069:22)
at i18n.phonenumbers.PhoneMetadata.getDescriptor (..../node_modules/google-libphonenumber/dist/libphonenumber.js:2946:117)
at goog.proto2.Message (..../node_modules/google-libphonenumber/dist/libphonenumber.js:1897:23)
at new i18n.phonenumbers.PhoneMetadata (..../node_modules/google-libphonenumber/dist/libphonenumber.js:2411:23)
at Object.<anonymous> (..../node_modules/google-libphonenumber/dist/libphonenumber.js:4432:56)
at Module._compile (module.js:435:26)
the google-libphonenumber version is 1.0.7 (latest) and it doesn't work with older versions either.
Please help!

Related

Session not created Selenium/webdriver when using Safari 12

Since upgrading to Safari 12, my automated scripts are now getting this error:
SessionNotCreatedError: Request body does not contain required parameter 'capabilities'.
(The error does not occur for other browsers).
I'm using the javascript webdriver bindings and, when I build webdriver, I use the withCapability key value pairs:
var capabs = {
'browserName' : 'Safari',
'version' : '12.0'
}
browserUnderTest = new webdriver.Builder().
withCapabilities(capabs)
.forBrowser('safari')
.build();
I think the problem is with the safari.js file itself, but I don't know enough about how it operates to pinpoint anything. Here is the full text of the error:
SessionNotCreatedError: Request body does not contain required parameter 'capabilities'.
at Object.throwDecodedError (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/lib/error.js:514:15)
at parseHttpResponse (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/lib/http.js:519:13)
at doSend.then.response (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/lib/http.js:441:30)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
From: Task: WebDriver.createSession()
at Function.createSession (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/lib/webdriver.js:769:24)
at Function.createSession (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/safari.js:253:41)
at createDriver (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/index.js:170:33)
at Builder.build (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/index.js:660:16)
at Object.<anonymous> (/Users/qualit/Documents/autotests/K8_autotest.js:354:6)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
Does anyone have any ideas about the cause of this or a fix?
This issue happens because Safari 12 uses a new W3C webdriver protocol (source) which appears to be incompatible with the latest stable selenium-webdriver package (v3.6)
safaridriver can be passed a --legacy flag to use the old protocol. Directly on the command line this would be done like: /usr/bin/safaridriver --legacy
This flag can be set on the driver in your node program as follows:
const webdriver = require('selenium-webdriver');
const safari = require('selenium-webdriver/safari');
new webdriver.Builder()
.usingServer(await new safari.ServiceBuilder().addArguments('--legacy').build().start())
.forBrowser('safari')
.build();
Here's documentation on the ServiceBuilder API - https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/safari_exports_ServiceBuilder.html
A couple GitHub tickets cover this as well:
https://github.com/SeleniumHQ/selenium/issues/6431
https://github.com/SeleniumHQ/selenium/issues/6026
This will also work if you get an error for 'await' when trying #mjdease solution above.
new webdriver.Builder()
.usingServer(new safari.ServiceBuilder().addArguments('--legacy').build().start())
.forBrowser('safari')
.build();

alternative to 'new Image()' of browser implementation into node-webgl javascript implementation?

Currently I am using a webGL based browser implementation code at client end. It is working perfectly. But, I want to use the same code at server end. Yes, this is not browser based, pure javascript code using node-webgl library.
While doing thisI am facing a problem.
new Image() is identified by browser, but at server side I am getting error Image is not defined. Below is the error I have attached. There are also additional two errors I am looking into it.
C:\Users\z003npra\Desktop\node>node exp.js
Status: Using GLEW 1.13.0
Linking ./simple.vert+./simple.frag
------------
Vertex info
-----------
(0) : error C5145: must write to gl_Position
Linking ./raycast.vert+./raycast-color.frag
------------
Vertex info
-----------
(0) : error C5145: must write to gl_Position
undefined:346
gl.tf_img = new Image();
^
ReferenceError: Image is not defined
at initTexture (eval at <anonymous> (C:\Users\z003npra\Desktop\node\exp.js:1
5:9), <anonymous>:346:18)
at volumerc_main (eval at <anonymous> (C:\Users\z003npra\Desktop\node\exp.js
:15:9), <anonymous>:392:2)
at Object.<anonymous> (C:\Users\z003npra\Desktop\node\exp.js:17:1)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:974:3
I tried another method installing canvas i.e npm install canvas and access it's Image object element: However, I am getting other error, looks like it is not compatible. At start I have defined
var Canvas1 = require('canvas')
, Image = Canvas1.Image;
The error is below,
C:\Users\z003npra\Desktop\node>node exp.js
Status: Using GLEW 1.13.0
Linking ./simple.vert+./simple.frag
------------
Vertex info
-----------
(0) : error C5145: must write to gl_Position
Linking ./raycast.vert+./raycast-color.frag
------------
Vertex info
-----------
(0) : error C5145: must write to gl_Position
C:\Users\z003npra\Desktop\node\node_modules\node-webgl\lib\webgl.js:806
throw new TypeError('Expected texImage2D(number target, number level, numb
er internalformat, number format, number type, Image pixels)');
^
TypeError: Expected texImage2D(number target, number level, number internalforma
t, number format, number type, Image pixels)
at Object.texImage2D (C:\Users\z003npra\Desktop\node\node_modules\node-webgl
\lib\webgl.js:806:13)
at handleLoadedTexture (eval at <anonymous> (C:\Users\z003npra\Desktop\node\
exp.js:15:9), <anonymous>:330:5)
at gl.tf_img.onload (eval at <anonymous> (C:\Users\z003npra\Desktop\node\exp
.js:15:9), <anonymous>:349:3)
at Image.src (C:\Users\z003npra\Desktop\node\node_modules\canvas\lib\image.j
s:30:17)
at initTexture (eval at <anonymous> (C:\Users\z003npra\Desktop\node\exp.js:1
5:9), <anonymous>:351:16)
at volumerc_main (eval at <anonymous> (C:\Users\z003npra\Desktop\node\exp.js
:15:9), <anonymous>:392:2)
at Object.<anonymous> (C:\Users\z003npra\Desktop\node\exp.js:17:1)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
Any other alternative to imitate the Image type in node-webgl based implementation?
Use Image from node-webgl library: var Image = require("node-webgl").Image;

How to find the location of a javascript syntax error programmatically?

I am loading a Node.js module using require. This throws a Syntax Error (an Error object).
Is there a way to get the location in the file where the error occurred?
I can see the stack (below) but I don't have any location information. I know I can use substack's node-syntax-error, but is there a way to get similar location info from the Javascript Error object?
SyntaxError: Unexpected identifier
at Module._compile (module.js:437:25)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
... // the rest is in my code
EDIT:
According to Vadim's comment below, yes that is what I am tempted to do. I see that node throws nice errors. Having a test.js file that contains only abc you get an error from node saying
ReferenceError: abc is not defined
at Object.<anonymous> (test.js:1:63)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
Now the question is, is there a node API to do get this error (that the node module.js module uses) such that I don't have to child_process.spawn('node', ['test.js'])?
You can simple run node with file that contains SyntaxError and see console output.
Error.stack
Errors have a "stack" property that stores the stack trace.
try {
throw new Error("with some message");
}
catch(err) {
// print error's stack trace to stder
console.error(err.stack);
}
running this on a file called "/home/myusername/test.js"
node /home/myusername/test.js
will output the following
Error: with some message
at Object.<anonymous> (/home/myusername/test.js:2:11)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
#laconbass answer works for me.
err.stack
I tried a blog framework and I got : 500 Internal Server Error. Hopefully I put a console :
app.use(function(error, req, res, next) {
res.status(500).render('500');
console.log(error);
});
and I could see the error which was not descriptive:
TypeError: Cannot read property 'replace' of undefined
After several minuts of research I found this answers, So I tried :
app.use(function(error, req, res, next) {
res.status(500).render('500');
console.log(error.stack);
});
and I could see the source point of error : (Object.exports.replace)
TypeError: Cannot read property 'replace' of undefined
at Object.exports.replace (/.../some_folder/node.js-blog-engine/node_modules/swig/lib/filters.js:411:15)
at eval (eval at <anonymous> (/.../some_folder/node.js-blog-engine/node_modules/swig/lib/swig.js:498:13), <anonymous>:41:63)
at Object.exports.each (/.../some_folder/node.js-blog-engine/node_modules/swig/lib/utils.js:45:11)
at eval (eval at <anonymous> (/.../some_folder/node.js-blog-engine/node_modules/swig/lib/swig.js:498:13), <anonymous>:26:10)
at Object.eval [as tpl] (eval at <anonymous> (/.../some_folder/node.js-blog-engine/node_modules/swig/lib/swig.js:498:13), <anonymous>:85:3)
at compiled (/.../some_folder/node.js-blog-engine/node_modules/swig/lib/swig.js:619:18)
at /.../some_folder/node.js-blog-engine/node_modules/swig/lib/swig.js:559:20
at /.../some_folder/node.js-blog-engine/node_modules/swig/lib/swig.js:690:9
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
I know that this is not a syntax error, but could be works to find the location of a javascript/node error.
I am a novice in nodejs.
I hope this helps.
You can use the stacktracey library (note: I'm the author of this library).
It prints nice callstacks along with source code lines, and also parses the SyntaxError output (in Node higher than v4).
For example, when trying to require this file (named test_files/syntax_error.js):
// next line contains a syntax error (not a valid JavaScript)
foo->bar ()
...the pretty printed call stack for the error thrown would be:
at (syntax error) test_files/syntax_error.js:2 foo->bar ()
at it test.js:184 try { require ('./test_files/syntax_error.js') }
at runCallback timers.js:781
at tryOnImmediate timers.js:743
at processImmediate [as _immediat timers.js:714
...where the first line is generated from parsing the raw output from the util.inspect call in Node.
The library also provides the full API access to the contents of a parsed call stack, so you can tune the output to whatever you want.

Node.js Cannot find module 'tcp'

node is crashing at the following line:
var tcp = require('tcp'),
error text:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'tcp'
at Function._resolveFilename (module.js:334:11)
at Function._load (module.js:279:25)
at Module.require (module.js:357:17)
at require (module.js:368:17)
at Object.<anonymous> (C:\Program Files\nodejs\websocket\websocket.js:11:11)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Module.require (module.js:357:17)
What is the problem? I found the source on the Internet, and the author, and the visitors also can run it...
Try require('net') instead:
$ node
> var tcp = require('tcp');
The 'tcp' module is now called 'net'. Otherwise it should have a similar interface.
> var tcp = require('net');
> $
Others are able to run, may be because they are using Node module when 'tcp' was there...
Now its called 'net', but its all the same thing no need of checking..
If you want to cross check for your more information, here are the links:
1.http://nodejs.org/api/net.html
2.https://github.com/joyent/node/blob/master/lib/net.js

Why can't I get an object prototype name in node.js

When I run the following code:
var os = require('os');
var sys= require('sys');
var ostype = os.type() + " ";
sys.puts(ostype.prototype.toString());
sys.puts("\n");
I get the following error:
node.js:116
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot call method 'toString' of undefined
at Object.<anonymous> (/home/Maria Dillon/test.js:5:27)
at Module._compile (module.js:374:26)
at Object..js (module.js:380:10)
at Module.load (module.js:306:31)
at Function._load (module.js:272:10)
at Array.<anonymous> (module.js:393:10)
at EventEmitter._tickCallback (node.js:108:26)
If I understand 15.2.4.2 of ECMA-262 3rd edition, this should work.
PS I am running node.js 0.5.0pre which I built myself on Cygwin.
Because ostype is an string, which is a primitive value. Here you'll find more information about it.
Good luck!

Categories