0

I am setting up a randomizer for my website using nodejs, but I keep getting a SyntaxError at the end of my script. I personally cannot find it and request help if available!

So far I have messed around with looking upwards to see if the error is further in the code and found nothing.

function time() {
  return parseInt(new Date().getTime()/1000)
}

function generate(count) {
    return crypto.randomBytes(count).toString('hex');
}

function array_limit(wartosc){
  if(chat_history.length==25){
    chat_history.shift();
    chat_history.shift();
  }
  chat_history.push(wartosc);
}

function jp_limit(wartosc){
  if(jpWinners.length==10){
    jpWinners.shift();
  }
  jpWinners.push(wartosc);
}
function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min);
} //this is the error line

I believe this should run just fine, my console output is below, maybe I am making a nube mistake but am seriously considering checking in to my nearest eye-doctor! :

    :2241
});
^

SyntaxError: Unexpected token }
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:617:28)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3

Edit1: Current version is version (8.16.0-1nodesource1).

Config.js

var config = {};

config.db = '';
config.host = '';
config.user = '';
config.password = '';

config.admin = '';
config.botsteamid = {bot1:''};
config.identitysecret = '';
config.sharedsecret = '';
config.polling_interval  = 5000;

config.bot_username = '';
config.bot_password = '';

config.manager_domain = '';
config.manager_lang = 'en';
config.manager_cancelTime = 60000;

module.exports = config;

I removed some sensitive data*

pigeon
  • 9
  • 1
  • 3
  • 3
    Welcome to SO! I notice that your error doesn't match the code, which has no such `});`. Can you clarify with a [mcve]? – ggorlen Jun 23 '19 at 02:37
  • Your code looks fine, probably some of these tools you're using to compile your bundle (or is it some node loader module like `ts-loader`) adding some noise. Is this the only file in your project? What do you use to run/build it? Is there any configuration file? – alx Jun 23 '19 at 02:38
  • @alx There is a config file, to run it I am using nodejs "filename" – pigeon Jun 23 '19 at 02:41
  • Can you add node version and config file to your question, please? And if there is package.json, that would be great to see too. – alx Jun 23 '19 at 02:42
  • 1
    @ggorlen problem is this file is nearing 2241 lines and a correct recreation of the problem wouldn't be possible as I cant see a problem, the }); doesn't match and is why I am stumped. – pigeon Jun 23 '19 at 02:44
  • 3
    I understand, but it seems unlikely that people who can't see the code will be able to determine the problem. How about http://www.balancebraces.com/? – ggorlen Jun 23 '19 at 02:45
  • 2
    This question has error message exactly like yours (different stack trace, tho): https://stackoverflow.com/questions/50042906/syntaxerror-unexpected-token-at-exports-runinthiscontext-vm-js5316-in-ela?rq=1. Re proflem file, that's why @ggorlen asked for *minimal* reproducible example -- remove functions and pices of code from that file until you have minimal code that shows the same error. – alx Jun 23 '19 at 02:46
  • 1
    Well, sorry for being unclear, I was talking about config file that alters node behavior, like webpack.config.js, or ts-config.json, or package.json -- that kind of thing. These files (if present in your project) would show exact stack that is used when you run your file. – alx Jun 23 '19 at 02:48
  • @alx Those would not be present in my project. – pigeon Jun 23 '19 at 02:52
  • Well, if you can't provide full file or it's shortened version which reproduces the issue, I can't see how we can help you. Error message says that closing curly brace is unexpected. This means somewhere above that place there is another closing curly brace -- one that was misplaced (or maybe some opening curly was accidentally removed). That site linked above could help you to see if that's true, I guess. Can't see what else can be done here. – alx Jun 23 '19 at 02:56

1 Answers1

0

Try moving the contents of your webpack.config.js file to a next.config.js file

Jonathan Beadle
  • 418
  • 2
  • 7