-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rcon is not a constructor #13
Comments
How are you importing the package? What language are you using (JS/TS)? |
JS. I've never used TS before- is there something obvious I'm missing because I'm using JS? |
No, TS and JS are similar in usage, though TS uses If you're following the README, then it's a bit off for JS when using non-modules: const Rcon = require('srcds-rcon'); // Use require instead of import when using native Node.js
const server = new Rcon({ host: '127.0.0.1', port: 25010 });
try {
await server.authenticate('your_rcon_password');
console.log('authenticated');
let status = await server.execute('status'); // You can read `status` reponse
server.execute('mp_autokick 0'); // no need to read the response
} catch(e) {
console.error(e);
} Also, you should ensure you're on the latest version of srcds-rcon, anything under |
Yeah I thought the |
Oh, you're using If you want to continue using that library, go to this URL or continue to use this library by using these commands:
A bit of a confusing naming scheme, but this'll fix your issue! |
LOL whooooops. Well I just switched it but I somehow still am back where I started. I am still getting the exact same error. I'm using the code you posted above, with the exception of using the new naming
gives me
|
Alrighty, I'll have to try this tomorrow then. I'll get back if I find a solution. |
The problem: // rcon.js, line 238
// Cannot be read by the module system
exports.default = RCON; When converting this to use // rcon.js, line 238
module.exports = RCON; I have recreated this issue by doing the following: // app.js
const Rcon = require("rcon-srcds");
const server = new Rcon({
host: "my.server.here"
});
(async () => {
await server.authenticate("password");
console.log(await server.execute("status"));
return await server.disconnect();
})();
/*
Expects:
hostname: my_server_here
version : ...
Gets:
const server = new Rcon({
^
TypeError: Rcon is not a constructor
*/ Doing the same thing in TypeScript will not throw this error, since it the resulting code is compiled. Tested with same example as above, and it works as expected. You can either use TypeScript, which is a superset of JavaScript, or modify the lines as decribed below. The solution: Because this library is written in ES6, the tsc compiler converts the // Wrong
const Rcon = require('rcon-srcds');
// Right
const Rcon = require('rcon-srcds').default; This isn't necessarily a bug with the library, just how tsc compiles the source code. |
Can this issue be closed? |
Not sure if I'm doing something wrong... but copying and pasting either example and running it gives me an error saying Rcon is not a constructor.
The text was updated successfully, but these errors were encountered: