I am trying to run following code===>
var webdriverio = require('webdriverio');
var options = { desiredCapabilities: { browserName: 'chrome' } };
var client = webdriverio.remote(options);
client
.init()
.url('http://www.webdriveruniversity.com/')
.click('#login-portal')
.getTitle().then(function(title) {
console.log('Title is: ' + title);
})
.end();
The output I am getting as follows. Not sure how to solve it.
const remote = async function (params = {}, remoteModifier) {
^^^^^^^^
SyntaxError: Unexpected token function
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\user\Desktop\webdriverFramework\loginPortal
Test.js:1:81)
It seems you are trying to use a library that uses async functions with an old Node.js version that does not support them. Please, run node -v and compare the Node.js version with the async functions support table.
Related
Im developing a nodejs application that needs to register to the AWS service discovery on the app start. I'm using the #aws-sdk/client-servicediscovery lib in my node application. As a reference, I am using the code from here: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-servicediscovery/index.html.
const { ServiceDiscoveryClient, CreateHttpNamespaceCommand } = require("#aws-sdk/client-servicediscovery");
const client = new ServiceDiscoveryClient({ region: "xxx" });
const params = {
"ServiceId":"xxx",
"InstanceId":"xxx",
"CreatorRequestId":new Date(new Date().toUTCString()),
"Attributes": {
AWS_INSTANCE_IPV4: "xxx.xx.xx.xx",
AWS_INSTANCE_PORT: xxx,
service: "xxx",
}
};
const command = new CreateHttpNamespaceCommand(params);
client.send(command).then(
(data) => {
console.log(data)
},
(error) => {
console.log(error)
}
);
While running the app, getting these errors.
/application/node_modules/#aws-sdk/shared-ini-file-loader/dist-cjs/slurpFile.js:5
const { readFile } = fs_1.promises;
^
TypeError: Cannot destructure property `readFile` of 'undefined' or 'null'.
at Object.<anonymous> (/application/node_modules/#aws-sdk/shared-ini-file-loader/dist-cjs/slurpFile.js:5:27)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/application/node_modules/#aws-sdk/shared-ini-file-loader/dist-cjs/loadSharedConfigFiles.js:8:21)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
I am new to the AWS SD so need some help registering my service to the service discovery. Thanks in advance!
I'm currently running a Mocha test of my Solidity contract but it throws error which is related to compiler code.
C:\eth\compile.js:8
modules.exports = solc.compile(source).[];
SyntaxError: Unexpected token '['
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\eth\test\inbox.test.js:5:31)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.exports.requireOrImport (C:\eth\node_modules\mocha\lib\esm-utils.js:42:12)
at Object.exports.loadFilesAsync (C:\eth\node_modules\mocha\lib\esm-utils.js:55:34)
at Mocha.loadFilesAsync (C:\eth\node_modules\mocha\lib\mocha.js:473:19)
at singleRun (C:\eth\node_modules\mocha\lib\cli\run-helpers.js:125:15)
at exports.runMocha (C:\eth\node_modules\mocha\lib\cli\run-helpers.js:190:10)
at Object.exports.handler (C:\eth\node_modules\mocha\lib\cli\run.js:362:11)
at C:\eth\node_modules\mocha\node_modules\yargs\build\index.cjs:443:71
The compiler itself is:
const path = require('path');
const fs = require('fs');
const solc = require('solc');
const inboxPath = path.resolve(__dirname, 'contracts', 'inbox.sol');
const source = fs.readFileSync(inboxPath, 'utf8');
modules.exports = solc.compile(source).[:Inbox];
You need to pass the JSON-stringified options object (to the compile() function), not just the text source. See the example in the readme.
Your solc.compile(source).[:Inbox] code has syntax errors (combining access to property with . and array with [) and logical errors (undefined :Inbox, incorrect path to the compiled result, trying to access a JSON string as an object).
Asssuming that inbox.sol contains contract Inbox that is the main contract you want to compile, this is a working code replacement for the last line in your question:
const options = {
language: 'Solidity',
sources: {
'inbox.sol': {
content: source
}
},
settings: {
outputSelection: {
'*': {
'*': ['*']
}
}
}
};
const compiledRaw = solc.compile(JSON.stringify(options));
const compiledObj = JSON.parse(compiledRaw);
const compiledInboxContract = compiledObj.contracts['inbox.sol']['Inbox'];
//console.log(compiledInboxContract)
module.exports = compiledInboxContract;
I am trying to run the following code with node.
var webdriverio = require('webdriverio');
var options = { desiredCapabilities: { browserName: 'chrome' } };
var client = webdriverio.remote(options);
client
.init()
.url('http://www.webdriveruniversity.com/')
.click('#login-portal')
.getTitle().then(function(title) {
console.log('Title is: ' + title);
})
.end();
I am getting this error
DEBUG wdio-config: #wdio/sync not found, runn
ing tests asynchronous
C:\Users\Adnan\Desktop\webdriverFramework\loginPortalTest.js:6
.init()
^
TypeError: client.init is not a function
at Object.<anonymous> (C:\Users\Adnan\Desktop\webdriverFramework\l
oginPortalTest.js:6:6)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:7
00:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
How can I resolve this? Previously I had the issue with version. But I upgraded to new version.
If I understand correctly, you lack #wdio/sync and your runner toggles into asynchronous mode. So webdriverio.remote(options) returns promise that has not .init() method.
My code is as shown below:
app.js
const app = express();
const itemsRouter = require('./routes/items.js');
app.use(bodyParser.urlencoded({
extended: true
}));
app.use('/items', itemsRouter);
items.js
const router = require('express').router;
router.get('/itemTest', (req, res) => {
res.json({
sucess: true
});
console.log(`the parametrs are ${req.body.item_name} ${req.body.item_post}`);
});
module.exports = router;
But here somehow, I am not able to get the router working and it says that can not read property 'get' of undefined.
the error stack is as shown below:
TypeError: Cannot read property 'get' of undefined
at Object.<anonymous> (C:\Users\anand\quFlipApi\routes\items.js:5:7)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\anand\quFlipApi\app.js:33:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
There are two problems here:
It's express.Router and not express.router.
You need to create a new instance of express.Router (e.g. var router = new express.Router()) instead of trying to using the constructor directly as an instance.
I was trying to run a MQTT server in nodejs on Ubuntu 14.04 LTS
var mosca = require('mosca')
var settings = {
port: 1883,
persistence: mosca.persistence.Memory
};
var server = new mosca.Server(settings, function() {
console.log('Mosca server is up and running')
});
server.published = function(packet, client, cb) {
if (packet.topic.indexOf('echo') === 0) {
return cb();
}
var newPacket = {
topic: 'echo/' + packet.topic,
payload: packet.payload,
retain: packet.retain,
qos: packet.qos
};
console.log('newPacket', newPacket);
server.publish(newPacket, cb);
}
it is throwing following error:
/home/ubuntu/node_modules/mosca/node_modules/qlobber/lib/qlobber.js:227
for (w of st.keys())
^^ SyntaxError: Unexpected identifier
at Module._compile (module.js:439:25)
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 Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/ubuntu/node_modules/mosca/node_modules/qlobber/index.js:3:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
Can anyone help what is that I am doing wrong?
of is a keyword in the newer ECMAScript spec, so it appears that the qlobber module used by mosca requires something newer than nodejs 0.10.x