Javascript Node - Showing errors on nightmare module nightmare.js - javascript

I can't work out why the library I have installed (nightmare is showing me errors). The errors are mainly on lines that contain :
=>
the error shows as expression expected.
when running my program I get this error from the nightmare.js:
return endInstance(self, () => fn.apply(self, doneargs));
^
TypeError: Cannot read property 'apply' of undefined
I get these errors too:
electronLog.stdout(data);
expected :
In my code I can't use statements like this either:
.evaluate(() =>
document.querySelector('#zero_click_wrapper .c-info__title a').href
)
Error: statement expected.
Any ideas would be much appreciated. All my other node modules are fine.

Related

Types of OkPacket[], FieldPacket[] of mysql2 in node.js

I'm using mysql2 in node.js.
And I define a variable that receives a result of a delete query, runs the query and displays a part of the result like below.
let deleteRes: [OkPacket[], FieldPacket[]] = [[], []];
deleteRes = await mysqlConnection.query<OkPacket[]>(`DELETE FROM tableName WHERE data1 = ? AND data2 = ?`, [data1, data2]);
console.log(deleteRes[0].affectedRows);
However, a compile error occurred at the console.log line above, when I compile it.
Error:(57, 39) TS2339: Property 'affectedRows' does not exist on type 'OkPacket[]'.
But, the code above works properly when I run the code.
Why does the compile error occur?
For testing, I changed the console.log line to below.
console.log(deleteRes[0][0].affectedRows);
So, the compile error did not occur, but an error occurred when I run the code like below.
TypeError: Cannot read properties of undefined (reading 'affectedRows')
Is there a way to resolve both errors at one time?
OS: MacOS v11.6.7.
IDE: IntelliJ IDEA 2022.1.
Typescript: v4.7.4.
Node.js: v16.17.0

What's this error ERROR Cannot prepare tests due to an error. TypeError: Cannot read property 'Date' of undefined?

Getting started on writing basic tests using TestCafe.
Objective open a web page and get its title. Getting below:
fixture (`Init Tests`)
.page(${data.baseURL});
test('Check Initial pg', async t =>(){
await t
.expect(Selector("title").innerText).eql('XXXXXXX');
});
}
The error message:
ERROR Cannot prepare tests due to an error.
is emitted when TestCafe cannot transpile your test code. This means there is a syntax error in test code.
Your code should look like this:
fixture ('Init Tests')
.page('http://devexpress.github.io/testcafe/example/');
test('Check Initial pg', async (t) => {
await t.expect(Selector('title').innerText).eql('XXXXXXX');
});

Uncaught ReferenceError for constant defined in same file

I'm using remark-math to render maths equations from Markdown. This has previously been working without a hitch, however after I refactored some seemingly unrelated code, I now get the following exception:
Uncaught ReferenceError: INLINE_MATH_DOUBLE is not defined
at Of.inlineTokenizer (inline.js:12)
at Of.tokenize [as tokenizeInline] (tokenizer.js:111)
at Of.atxHeading (heading-atx.js:148)
at Of.tokenize [as tokenizeBlock] (tokenizer.js:111)
at Of.parse (parse.js:41)
at Function.parse (index.js:275)
at pipelineParse (index.js:22)
at wrapped (index.js:93)
at next (index.js:56)
at Object.run (index.js:30)
The relevant code from ./node_modules/remark-math/inline.js looks like the following:
const ESCAPED_INLINE_MATH = /^\\\$/
const INLINE_MATH = /^\$((?:\\\$|[^$])+)\$/
const INLINE_MATH_DOUBLE = /^\$\$((?:\\\$|[^$])+)\$\$/ // << defined here?
module.exports = function inlinePlugin (opts) {
function inlineTokenizer (eat, value, silent) {
let isDouble = true
let match = INLINE_MATH_DOUBLE.exec(value) // << line 12, error here
// ...remaining code
The constant appears to be defined in scope!
I'm building using webpack and the chentsulin/electron-react-boilerplate template. Any hints as to why this kind of exception would suddenly be happening? (I've tried a complete reinstall of node_modules.)
maybe some issues happen from webpack building.
if the error still happen, and you want to avoid it, you can use this
GLOBAL.INLINE_MATH_DOUBLE = /^\$\$((?:\\\$|[^$])+)\$\$/
I reinstalled the dependencies with yarn instead of npm and the issue went away.

node.js ParseError - which file is the error thrown in?

I've got quite a big library written in node.js, too big to paste here (>20 files). I've got a try..catch that catches the error, I debug the catch part and I console.log the error as below:
{ [ParseError: value.key.split is not a function]
message: 'value.key.split is not a function',
path: [ 'properties', 'statement1' ],
name: 'ParseError' }
The thing is - I don't know which file is that and I'm somehow unable to debug it. Can I access the source file (line, preferably) where this error was thrown? What node.js returns is the actual line that it tried to execute, but I can hardly spot where it is... Any suggestions would be welcome.
Try
console.dir( error );
on error instead. You also might try logging the stack property explicitly:
console.log( error.stack );

When does Node's REPL get "stuck"?

Sometimes, when you type enter after a correct finished statement, the REPL waits for more :
> var f; function(){};
...
When exactly does that happen ? I didn't found any documentation on that.
Your code is not correct. When run from a file, a syntax error is reported:
SyntaxError: Unexpected token (
There was a bug in REPL where in the case of a syntax error, REPL assumed the code to evaluate is not complete and would span multiple lines. Regardless of the type of syntax error.
The issue was fixed in v0.11.7 by commit 9ef9a9d. See the commit message for more details.

Categories

Resources